Here is the situation :
class Activity < ApplicationRecord
has_many :activity_amenities
end
class Amenity < ApplicationRecord
has_many :activity_amenities
has_many :activities, through: :activity_amenities
end
class ActivityAmenity < ApplicationRecord
belongs_to :activity
belongs_to :amenity
end
So basically i have Activities
that have Amenities
. The reason for me to use a has_many :through
association is because I want to create basic Amenities
and each Activity' amenities will have a description proper to the Activity.
So, I want to create new Amenities
straight in the creation/edition of an Activity. This image should illustrate it very well :
So when I click on Add amenity
button, it should add new select/input group.
Then when I click on create, it should create all the ActivityAmenities
and associate them with the Activity
model.
Any idea How this should be done (in the Controller and in the View) ? Couldn't find anything really...
ps : note that I'm using simple-form gem for the forms