Hi everyone,
I have a little problem:
I’d like to convert this html code in Rubyonrails code!
Matteo
If I write:
<%= link_to ‘Matteo’, :controller=>‘welcome’, :action=>‘my_name’,
:class=>“a.two” %>
it doesn’t work.
Would you mind telling me what I should do?
THANKS!
Matteo
the third parameter of the link_to method accepts html options
so you can do:
<%= link_to ‘Matteo’, {:controller=>‘welcome’, :action=>‘my_name’},
{:class=>‘two’} %>
i’m pretty new to RoR myself, but i think the curly braces are what you
are missing
luke
Matteo wrote:
Hi everyone,
I have a little problem:
I’d like to convert this html code in Rubyonrails code!
Matteo
If I write:
<%= link_to ‘Matteo’, :controller=>‘welcome’, :action=>‘my_name’,
:class=>“a.two” %>
it doesn’t work.
Would you mind telling me what I should do?
THANKS!
Matteo
This got me the first time too. The thing to notice is the {}
parameters in the API doc.
link_to(name, options = {}, html_options = nil,
*parameters_for_method_reference)
Rails will be clever if you do this:
link_to ‘blah’, :controller => ‘cont’, :action => ‘act’
it will interpret it as a string parameter and a hash i.e.
link_to ‘blah’, {:controller => ‘cont’, :action => ‘act’}
If you want to use the html_options hash then you have to do as Luke
says and put the 2nd set of braces in yourself
link_to ‘blah’, {:controller => ‘cont’, :action => ‘act’}, {:class =>
‘class’}
Hope that helps
Luke