On Wed, Jan 30, 2013 at 5:34 PM, Abdullah Esmail
<[email protected]>wrote:
> 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!
>
> Thank you.
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msg/rubyonrails-talk/-/72HFVK-JilIJ.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
--
-------------------------------------------------------------
visit my blog at http://jimlabs.heroku.com
--
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 [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.