Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert <%= link_to "Upgrade", :settings, :class => "button" %> to a block in Rails 3?

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 ?

like image 929
marcamillion Avatar asked Mar 15 '11 02:03

marcamillion


People also ask

What version of Ruby does Rails use?

Rails Rails 4 requires Ruby 1.9 or later. Rails 5 requires Ruby 2.2 or later. Rails 6 requires Ruby 2.5 or later.


1 Answers

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.

like image 125
Matchu Avatar answered Sep 29 '22 10:09

Matchu