Rails: complex html <a> in link_to helper
How do I convert this link if I wanted to use the rails <%= link_to %> helper?
Here is my link:
<a id="landing_link" href="#landing"><div id="headerlogo"></div></a> Another question is that a link is an anchor link. In link_to from another page, how would I link it to a page (like an index) and then to an anchor?
+4
4 answers
You can use the do block for link_to:
Documentation their example:
<%= link_to(@profile) do %> <strong><%= @profile.name %></strong> -- <span>Check it out!</span> <% end %> # produces the following HTML: <a href="/profiles/1"> <strong>David</strong> -- <span>Check it out!</span> </a> In your case , <a id="landing_link" href="#landing"><div id="headerlogo"></div></a> It becomes :
<%= link_to '#landing', :id => 'landing_link' do %> <div id="headerlogo"></div> <% end %> +4