Rails 3 - link_to with image_tag + text

痴心易碎 提交于 2019-12-02 22:26:17

Try this.

<%= link_to image_tag('/images/image.png') + "some extra text", url_for({:controller => 'controller_name', :action => 'action_name'}), :class => 'quick', :remote => true %>

A slightly sexier solution?

<%= link_to image_tag("image.png", :alt => "Image Description", :class => "css"), root_path %>

Try this:

<%= link_to (image_tag('image.png') + text, 
        url_for({:controller => 'controller_name', :action => 'action_name'}), 
            :class => 'quick', 
            :remote => true) %>

The first argument is the text part and with image_tag you create HTML, but you can easily append stuff.

I used the following and it works just fine:

<%= link_to image_tag("logo.jpg"), controller: 'welcome' %>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!