简体   繁体   中英

In rails 3 how do you have text and image in link_to?

I want a link with text and an image. Before rails 3 internet tells me that you must do:

<%= link_to "my text"+image_tag("image.jpg"), {:controller=>:billets}, :class => 'link_to_blog'%>

However in rails 3 i have the code of the image displayerd in my web page instead of the image. Seems now, it escape the html code.

How can i do a link_to with text and image in rails 3?

<%= link_to ("my text"+image_tag("image.jpg")).html_safe, {:controller=>:billets}, :class => 'link_to_blog'%>

Or

<%= link_to {:controller => :billets}, :class => 'link_to_blog' do %>
  My text
  <%= image_tag "image.jpg" %>
<% end %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM