One model, two registrations, one form

42 views
Skip to first unread message

David Meneses

unread,
Feb 7, 2014, 5:24:46 PM2/7/14
to rubyonra...@googlegroups.com
Hi, how can i register two rows of the same model in one form?

--
Posted via http://www.ruby-forum.com/.

tamouse pontiki

unread,
Feb 7, 2014, 11:41:40 PM2/7/14
to rubyonra...@googlegroups.com
On Fri, Feb 7, 2014 at 4:24 PM, David Meneses <li...@ruby-forum.com> wrote:
> Hi, how can i register two rows of the same model in one form?

What, exactly, do you mean by "register" ?

Phillip

unread,
Feb 8, 2014, 5:02:28 AM2/8/14
to rubyonra...@googlegroups.com
The most direct way is to forget Rails and use HTML with or without ActionView::Helpers::FormTagHelper.

Walter Lee Davis

unread,
Feb 8, 2014, 4:43:42 PM2/8/14
to rubyonra...@googlegroups.com
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
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/fbe1676e-8da9-46c3-a7d4-59fbc12215fa%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Ehtsham Abbas

unread,
Feb 11, 2014, 7:19:41 AM2/11/14
to rubyonra...@googlegroups.com
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
<div id='user_wrapper'>
<%= text_field_tag "user[0][name]" %>.
</div>

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 = '<div id='user_wrapper'>
<input type="text" id= "user_'+count+'_name" name="user['+count+'][name]"
</div> '
$('user_wrapper').insert(fields);
}

Hope this will help?
Reply all
Reply to author
Forward
0 new messages