I have working code that uses select2 to accept multiple tags into the one input field. I used this solution to permit my parameter as:
params.require(:computer_service).permit( {:repairer_ids => []})
This works correctly. I recently set Rails to raise an error for unpermitted errors so I would be aware if any form data wasn't being saved:
#development.rb
config.action_controller.action_on_unpermitted_parameters = :raise
Since adding that setting Rails now raises an error found unpermitted parameters: repairer_ids
, even though the code works and the parameter repairer_ids are found and saved.
Sample parameters:
"computer_service"=>{ "repairer_ids"=>"1663,1726" }
UPDATE
If I change to params.require(:computer_service).permit( :repairer_ids )
then the first id is saved but not the second. I should point out that in my controller I am using code to convert the comma separated string into an array:
@computer_service.repairer_ids = repairer_ids.split(',')
I am doing this because the relationship between ComputerService and Repairer is a has_many through
#computer_service.rb
has_many :repairers, :through => :computer_service_repairers
and I have successfully saved multiple values to the computer_service_repairers through/join table by using multiple values in an array.