Multiple forms to create multiple records for multiple users

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?

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!