I'm looking to create a form that updates a User's has_many through relationship. To be more specific, each User has many Weekdays (the model is working perfectly) and I'd like to add a form to add extra weekdays, selectable from check boxes. For reference, the (abridged) model is:
class User < ActiveRecord::Base
has_many :user_weekdays, dependent: :destroy
has_many :weekdays, -> { uniq }, through: :user_weekdays
end
class Weekday < ActiveRecord::Base
has_many :user_weekdays
has_many :users, -> { uniq }, through: :user_weekdays
end
i.e. a 'User.find(1).weekdays' might currently return Sunday and Monday, though I'd like to have a form that provides a list of all the weekdays, with those selected pushed to the user.weekdays when it's submitted.
I'm presuming it should work something like User.find(params[:id]).weekdays << (the form entries) but don't know how to do this.
I'm pretty new to Rails, and am a little lost when it comes to any form out of the ordinary. How do I build this? I've had a hunt on SO but can't find anything definitive to apply. Any advice on how to implement this in the view and controller would be GREATLY appreciated. Thanks in advance, Steve.