Hi everyone, I have a little problem: I''d like to convert this html code in Rubyonrails code! <a class="two" href="welcome/my_name" target="_parent">Matteo</a> 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
the third parameter of the link_to method accepts html options
http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#M000378
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!
> <a class="two" href="welcome/my_name"
target="_parent">Matteo</a>
> 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
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---
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
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---