我有以下代码:
<%= 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标签?我错过了什么?
答案 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>