Hello, I''m having hard times on a very simple problem : how to provide a css class to a link_to tag ? I''m using this : <%= link_to ''Cancel'', :action => ''list'', :class => ''btn-cancel'' %> and RoR produces this : <a href="/gallery/list?class=btn-cancel">Cancel</a> I''ve read the doc of url_for several times but I still don''t see why it doesn''t work ? Thanks -- Posted via http://www.ruby-forum.com/.
Christian Klauser
2006-Apr-17 11:28 UTC
[Rails] Re: Please help : how to link_to() and css styles ?
> <%= link_to ''Cancel'', :action => ''list'', :class => ''btn-cancel'' %>Definition of link_to: link_to(title, url, options) The ruby interpreter thinks that :class belongs to the url. Try: <%=link_to Cancel, {:action => ''list''}, :class => ''btn-cancel'' %> -- Posted via http://www.ruby-forum.com/.
Thanks for the help, it works like a charm but I still don''t understand why the 3 comma delimited parameters ''Cancel'', :action => ''list'', :class => ''btn-cancel'' does not fit into title, url, options Why :action => ''list'', :class => ''btn-cancel'' are interpreted as the second parameter ? I thought that {:action => ''list'', :class => ''btn-cancel''} only would produce that !? -- Posted via http://www.ruby-forum.com/.
Chang Sau Sheong
2006-Apr-17 15:45 UTC
[Rails] Re: Please help : how to link_to() and css styles ?
I think it''s because if you don''t put braces around your parameters, the method thinks that anything after the first parameter is part of the second parameter. As a general rule if you have more than 2 parameters for link_to or the like kind of methods, you should put in braces to indicate exactly what you want. I believe this is part of Ruby''s programming idiom. Nuno wrote:> Thanks for the help, it works like a charm but I still don''t understand > why the 3 comma delimited parameters ''Cancel'', :action => ''list'', :class > => ''btn-cancel'' does not fit into title, url, options > > Why :action => ''list'', :class => ''btn-cancel'' are interpreted as the > second parameter ? I thought that {:action => ''list'', :class => > ''btn-cancel''} only would produce that !? > >-- Sau Sheong http://blog.saush.com http://read.saush.com http://jaccal.sourceforge.net