Generate array of textbox in Ruby on Rails -


i using below ruby code

<%= form_for :post, url:"/index" |f|%>     <%= f.text_field(:name) %> <% end %> 

this generates form textbox below

<input type="text" name="post[name]" id="post_name"> 

is there way generate fields array format such as:

<input type="text" name="post[name][]" id="post_name_1"> <input type="text" name="post[name][]" id="post_name_2"> <input type="text" name="post[name][]" id="post_name_3"> <input type="text" name="post[name][]" id="post_name_4"> : : <input type="text" name="post[name][]" id="post_name_n"> 

you can override name this

<%= f.text_field(:field_name, :name => "post[name][]") %> 

and this:

<%(1..n).each |i|%> <%= f.text_field(:name, :name => "post[name][]", :id => "post_name_#{i}") %> <%end%> 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -