Reputation: 55
I have two models Session and Speaker. Here one Session may have many Speakers and one Speaker may speak in many sessions, so I have used has_many relation, my models are looking like this
class Speaker < ActiveRecord::Base
has_many :session_speakers
has_many :sessions, :through => :session_speakers
end
class Session < ActiveRecord::Base
has_many :session_speakers
has_many :speakers, :through => :session_speakers
end
and the join table is
class SessionSpeaker < ActiveRecord::Base
belongs_to :session
belongs_to :speaker
end
the problem is when am selecting multiple speakers in session form speakers are getting stored in join table in console it is showing Unpermitted parameters: speaker_ids.
my session controller in activeadmin is like this
ActiveAdmin.register Session do
permit_params :speaker_ids, :title, :summary, :session_code, :session_type, :time_start_date, :time_start_time_hour, :time_start_time_minute, :time_end_date, :time_end_time_hour, :time_end_time_minute, :event_year_date, :event_year_time_hour, :event_year_time_minute
end
Please help me to solve this issue. how can I make store speakers details into join table
thanks.
Upvotes: 0
Views: 529
Reputation: 3732
To declare that the value in params must be an array of permitted scalar values map the key to an empty array:
Try to use speaker_ids: []
ActiveAdmin.register Session do
permit_params :title, :summary, :session_code, :session_type, :time_start_date, :time_start_time_hour, :time_start_time_minute, :time_end_date, :time_end_time_hour, :time_end_time_minute, :event_year_date, :event_year_time_hour, :event_year_time_minute, speaker_ids: []
end
Upvotes: 0