One model, two registrations, one form

Hi, how can i register two rows of the same model in one form?

On Fri, Feb 7, 2014 at 4:24 PM, David M. [email protected]
wrote:

Hi, how can i register two rows of the same model in one form?

What, exactly, do you mean by “register” ?

The most direct way is to forget Rails and use HTML with or without
ActionView::Helpers::FormTagHelperhttp://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html
.

There is also the nested form setup, but your objects will need a common
parent. Can you sketch out your use-case, including any related models?
There may be a simple solution that your question doesn’t trigger in
those of us who have read it.

Walter

Try to describe it more clearly.

Let me give you an example scenario:

Model is user. Where you want to register multiple users in same form.
Simple RHTML/HTML to display form and button to clone the form below.
You
can regenerate same html with javascript and name the text_field with
index
like this
HTML

<%= text_field_tag "user[0][name]" %>.

Each time you clone the form increase index+1 in your javascript
function.
When you submit a form you will receive hash with all users details.

*js function would be like *
function clone_form(){
var count = parseInt($(‘count’).value);
count = count+1;
$(‘count’).value = count;
var fields = ’


<input type=“text” id= “user_’+count+’_name”
name=“user[’+count+’][name]”
' $('user_wrapper').insert(fields); }

Hope this will help?