I'm trying to iterate through an array of which each entry will create an input field in a form made in ERB. I've set up a @loopcount integer that gets increased for every new entry in this array. I would like to use that increasing integer in fieldnames:
Item <input name="s_fieldname_<%= @loopcount %>" id="s_fieldname_<%= @loopcount %>" type="text" value="<%= field[0] %>" size="12"><br/>
Because of being inside the double quotations, that @loopcount is not taking. I'm guessing this is an escaping issue of some sort. %% did not work.
Edit: Add syntax
<% @fields.each do |field| %>
<span class="red"><%= field[0] %></span> - <%= field[1] %><br>
<strong>fieldname</strong> <input name="s_fieldname_#{@loopcount}" type="text" value="<%= field[0] %>" size="12"><br/>
<strong>show</strong> <input name="s_show_#{@loopcount}" type="checkbox" checked><br/>
<strong>required</strong> <input name="s_required_#{@loopcount}" type="checkbox"><br/>
<strong>description</strong> <input name="s_description_#{@loopcount}" type="text" value="" size="60"><br/>
<% @loopcount += 1 %>
<% end %>
Any ideas how I can achieve this? Cheers
Well, I don't know how this happened, but the first syntax now works upon replacement.
...name="s_fieldname_<%= @loopcount %>" type="text" value="<%= field[0] %>"...
I'm using Chrome for this, but Safari was also showing the same syntax result.
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.