简体   繁体   中英

Chaining link_to content_tag Image_tag in Rails

I have the following code:

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

however, I am getting the following error:

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

Is it possible to chain erb tags like this? What am I missing?

You should write the code for easier reading:

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

Output:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM