0

I have an array attribute in the form and wanting to iterate over this and append each index value to dom id. I've looked up in the API for use of dom_id but I can't locate one that deals with array attribute.

If dom_id is not meant for working with array index, is there any other way to get array indexes in the view?

<div id="ingredient<%= dom_id(?) %>">

2 Answers 2

1

I guess you want something like following

<% array.each_with_index do |arr, index| %>
  <div id="ingredient<%= index %>">
<% end %>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. Worked perfectly
1
<% custom_array.each_with_index  do |item,index| %> 

 <div id="<%= ingredient_#{index} %>">  
       <!--other contents goes here -->
  </div> 

<% end %>

Otherwise you can try id = " ingredient_<%= index>"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.