How to create a multi-edit form in rails -
i need create multi-edit form in rails, so:
<form> <input type='text' name='input1'></input> <input type='text' name='input2'></input> <input type='text' name='input3'></input> <input type='text' name='input4'></input> <input type='text' name='input5'></input> <br> <input type='text' name='input1'></input> <input type='text' name='input2'></input> <input type='text' name='input3'></input> <input type='text' name='input4'></input> <input type='text' name='input5'></input> <br> <input type='text' name='input1'></input> <input type='text' name='input2'></input> <input type='text' name='input3'></input> <input type='text' name='input4'></input> <input type='text' name='input5'></input> <br>
... , on, "<submit>
" button @ end. 1 click of submit button @ end should collect values , parse them in controller.
i need know how generate multi-edit form in view. also, each row unique; i'd need know how assign unique identifier each of input tags guess; have unique id value use.
this trivial accomplish, need more information. how these fields related models? 1 model many fields, many instances of model or else?
what want in situation use form builder. generate input fields according naming convention parsed more useful format when gets controller. since have no information models, use hypothetical example:
class post < activerecord::base attr_accessible :title, :body, :author, :published_at end
create form using form_for
helper. give formbuilder object create input fields.
<% form_for :post |f| -%> <p> <%= f.label :title %> <%= f.text_field :title %> </p> <p> <%= f.label :body %> <%= f.text_area :body %> </p> <p> <%= f.label :author %> <%= f.text_field :author %> </p> <p> <%= f.label :published_at %> <%= f.datetime_select :published_at %> </p> <% end -%>
the key benefit of using helpers name
attribute of inputs generates. since body
belongs form post
given name attribute post[body]
. these attributes parsed following hash:
:post => { :title => "this title", :body => "this body", :author => "john doe", :published_at => "mon nov 15 2010 19:23:40 gmt-0600 (cst)" }
this means don't need manually copy fields model. can pass directly model#new
method:
@post = post.new(params[:post])
and validation checks. convention becomes indispensable when start nesting models inside 1 another.
see here more thorough guide form helpers.
Comments
Post a Comment