How do I convert <%= link_to “Upgrade”, :se

2020-06-17 09:02发布

问题:

I would like to produce this link:

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

So as far as I understand it I have to convert

<%= 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 %>

It gives me the following error:

undefined method `stringify_keys' for :settings:Symbol

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

How do I convert this to a block ?

回答1:

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.

Remove "Upgrade" and put it in the block.