Create a big tag in rails

I have this tag: <%= link_to 'Show', user_listing_url(listing.user, listing) %> , but instead of just saying "Show", I really want to place the HTML inside the <a> tag. Is it possible?

Example:

<a href=""><div><div><img /></div></div></a>

+4
source share
2 answers

yes you can pass the link_to block

try something like this:

 <%= link_to(user_listing_url(listing.user, listing)) do %> <div><div><img/></div></div> <% end %> 
+6
source

I totally recommend marflar to answer above.

However, I would add one comment, which is that if you use html elements in the link_to block, this can apply the default rails link style, which may be undesirable.

One option is to use the button_to link, but do not forget that the default method for this is POST, so specify the parameters as GET:

 button_to(user_listing_url(listing.user, listing), method: :get) do %> <div></div> <% end %> 
0
source

All Articles