Forum: Ruby on Rails Multiple forms to create multiple records for multiple users

Posted by Abdullah Esmail (Guest)
on 2013-01-30 15:10
(Received via mailing list)
Hello.
I have come across a scenario where I need to save multiple records for
multiple users on the same page.

User has_many :shifts
Shift belongs_to :user

I need to show multiple shifts for each user on the same page and the
administrator will just enter some values and click save.

Example:
user1: <shift1_value> - <shift2_value> - <shift3_value>
user2: <shift1_value> - <shift2_value> - <shift3_value>
user3: <shift1_value> - <shift2_value> - <shift3_value>
[save]

What's the best way to tackle this problem in rails?

Thank you.
Posted by Jim ruther Nill (jimboker)
on 2013-01-30 15:35
(Received via mailing list)
On Wed, Jan 30, 2013 at 5:34 PM, Abdullah Esmail
<abdullah.esmail@gmail.com>wrote:

> Example:
> user1: <shift1_value> - <shift2_value> - <shift3_value>
> user2: <shift1_value> - <shift2_value> - <shift3_value>
> user3: <shift1_value> - <shift2_value> - <shift3_value>
> [save]
>
> What's the best way to tackle this problem in rails?
>

This all depends on how you setup the form in your views.  I suggest you
create a spectific action, outside of the 7 crud actions, to handle the 
data
that you get when you do this.

As for the form, I think the names of the elements should be

shifts[][user_id] for the user_id
shifts[][shifts][] for the 3 shift values

you'll receive a hash that looks like

shifts: [{ user_id: 1, shifts: [1,2,3] }, { user_id: 2, shifts: [1,2,3] 
}]

on the controller. good luck!


> https://groups.google.com/d/msg/rubyonrails-talk/-....
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



--
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.