ruby-on-rails Rails - link_to with image_tag + text

pbossiut  于 5个月前  发布在  Ruby
关注(0)|答案(5)|浏览(38)
<%= link_to ((image_tag 'image.png'), 
        url_for({:controller => 'controller_name', :action => 'action_name'}), 
            :class => 'quick', 
            :remote => true) %>

字符串
这部分代码将生成我的image.png作为链接。我需要在这个图像中附加一些文本(image + text),我尝试了类似于a的东西:

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


和类似的方式,但这些尝试都以错误的语法信息结束.有人能帮助我,请,我应该如何设置它的权利?

ghhkc1vu

ghhkc1vu1#

试试这个.

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

字符串

yrefmtwq

yrefmtwq2#

更性感的解决方案?

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

字符串

yqyhoc1h

yqyhoc1h3#

试试这个:

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

字符串
第一个参数是文本部分,使用image_tag可以创建HTML,但可以轻松地追加内容。

jaxagkaj

jaxagkaj4#

我使用了以下方法,效果很好:

<%= link_to image_tag("logo.jpg"), controller: 'welcome' %>

字符串

yws3nbqq

yws3nbqq5#

我知道这太晚了,但也许有人想找到答案,所以。正确的答案是:

<%= link_to image_tag(product.image_url), line_items_path(product_id: product), method: :post, remote: true %>

字符串
在这种情况下,我们需要指定我们想要执行的确切操作,通过单击此图像,如果我们使用button_to helper,则不需要指定操作,但button helper不支持图像标记

相关问题