本文介绍了我如何转换 <%= link_to “Upgrade", :settings, :class =>“按钮"%>到 Rails 3 中的块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作这个链接:

<a href="/settings" class="button"><span class="magnifier icon"></span>Search</a>

据我所知,我必须转换

<%= link_to "Upgrade", :settings, :class => "button" %>

到一个块,但是当我这样做时:

To a block, but when I do this:

<%= link_to "Upgrade", :settings, :class => "button" do %>
   <span class="magnifier icon">Search</span>
<% end %>

它给了我以下错误:

undefined method `stringify_keys' for :settings:Symbol

但是,当我这样做时:"button" %> 效果很好.

However, when I do: <%= link_to "Upgrade", :settings, :class => "button" %> it works perfectly.

如何将其转换为块?

推荐答案

使用块时,第一个参数不再包含链接内容.该块负责.因此,它认为 "Upgrade" 是您链接的目的地,而 :settings 是您的选项哈希.

When using a block, the first argument no longer contains the link content. The block is responsible for that. Therefore, it thinks that "Upgrade" is your link's destination and :settings is your options hash.

删除Upgrade"并放入块中.

这篇关于我如何转换 &lt;%= link_to “Upgrade", :settings, :class =&gt;“按钮"%>到 Rails 3 中的块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 08:50