ruby on rails - How do I set the ID in a link_to tag in haml? -


i've tried

= link_to 'foo', :action => 'bar', :id => 'foobar' 

but id seems modify href, resulting in

<a href="controller/foobar/bar">foo</a> 

how set id correctly? can explain me why :id modifying href can understand what's going on behind scenes?

you have put :action => 'bar' inside hash.

= link_to 'foo', { :action => 'bar' }, :id => 'foobar' 

there example in docs put example same problem:

classes , ids css easy produce:

link_to "articles", articles_path, :id => "news", :class => "article" # => <a href="/articles" class="article" id="news">articles</a> 

be careful when using older argument style, literal hash needed:

link_to "articles", { :controller => "articles" }, :id => "news",      :class => "article" # => <a href="/articles" class="article" id="news">articles</a> 

leaving hash off gives wrong link:

link_to "wrong!", :controller => "articles", :id => "news", :class => "article" # => <a href="/articles/index/news?class=article">wrong!</a> 

this why it's better use new argument style, alias routes, more calling controllers , actions explicitly.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -