0

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.

Community
  • 1
  • 1
Marklar
  • 1,247
  • 4
  • 25
  • 48
  • 3
    Your `repairer_ids` aren't being received in an array form. Try `params.require(:computer_service).permit(:repairer_ids)` – SHS Mar 12 '15 at 07:02
  • Agree with @Humza - Looks like the the input is being submitted as a comma delimited string, not an array. – Mark Swardstrom Mar 12 '15 at 15:00
  • @Humza, thank you for your help. I forgot to put in my original question that I was manually converting to an array in my controller so I could use a has_many through relationship with a join table. My apologies. I have updated the question. – Marklar Mar 12 '15 at 21:21

0 Answers0