开发者

create large a tag in rails

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

Example:

开发者_Python百科

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


yes you can pass a block to link_to

try something like this:

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


I totally recommend marflar's answer above.

However I would add one comment which is that if you are using html elements within a link_to block this may apply rails default link styling which may not be desirable.

One alternative is to use a button_to link but don't forget the default method for this is POST so specify the options as GET:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜