Matteo
Matteo

Reputation: 1136

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?

Upvotes: 1

Views: 4402

Answers (1)

ole
ole

Reputation: 5233

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>

Upvotes: 2

Related Questions