【问题标题】:In rails 3 how do you have text and image in link_to?在 Rails 3 中,如何在 link_to 中包含文本和图像?
【发布时间】:2011-08-10 16:59:47
【问题描述】:

我想要一个带有文本和图像的链接。 在 rails 3 internet 告诉我你必须这样做之前:

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

但是,在 rails 3 中,我的网页中有显示图像的代码,而不是图像。现在看来,它转义了 html 代码。

如何在 rails 3 中使用文本和图像进行 link_to?

【问题讨论】:

    标签: ruby-on-rails hyperlink link-to


    【解决方案1】:
    <%= link_to ("my text"+image_tag("image.jpg")).html_safe, {:controller=>:billets}, :class => 'link_to_blog'%>
    

    或者

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

    【讨论】:

    • 我猜应该是 link_to ({:controller => :billets}, :class=> 'link_to_blog') 做
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多