在Rails中链接link_to content_tag Image_tag

时间:2014-07-05 23:33:23

标签: ruby-on-rails link-to content-tag

我有以下代码:

<%= link_to(content_tag(image_tag('img_blank.png', alt: "Continue"),:div, [class: "btn", id: "continue"])) %>

但是,我收到以下错误:

undefined method `each_pair' for [{:class=>"btn", :id=>"continue"}]:Array

是否可以像这样链接erb标签?我错过了什么?

1 个答案:

答案 0 :(得分:1)

您应该编写代码以便于阅读:

<%= link_to("/url") do %>
  <%= content_tag(:div, class: "btn", id: "continue") do %>
    <%= image_tag('img_blank.png', alt: "Continue") %>
  <% end %>
<% end %>

输出:

<a href="/url">
  <div class="btn" id="continue">
    <img alt="Continue" src="/images/img_blank.png">
  </div>
</a>