Reputation: 320
I've got a variety of attributes I'm trying to persist, and as they exist in params they look like this:
Parameters:
{"utf8"=>"✓", "authenticity_token"=>"5hUuVqqmPulYVPsCP6GF4Tya3QWpDQXBQJVckbDPxRA=",
"program"=>{"name"=>"Save categories", "description"=>"",
"category_ids"=>{"0"=>"53029921d2b38bf8da000015", "1"=>"", "2"=>""}, "eligibility"=>"",
"how_to_access"=>"", "street_address"=>"", "city"=>"", "state"=>"", "zip"=>"",
"neighborhood_ids"=>["", "52dda579d2b38bf39d000025", "52dda579d2b38bf39d00002e"],
"county"=>"", "phone"=>"", "email"=>"", "website"=>""}, "commit"=>"Update Program",
"id"=>"5320c2dbd2b38b90d7000004"}
Specifically, everything's working except the category_ids hash:
"category_ids"=>{"0"=>"53029921d2b38bf8da000015", "1"=>"", "2"=>""}
In my various controllers that utilize these categories to create and update, here's my strong parameters
def program_params
params.require(:program).permit(:name, :slug, :description, :cost, :min_age, :max_age, :how_to_access, :min_grade,
:max_grade, :start_date, :end_date, :notes, :tag_list, :eligibility,
:street_address, :state, :city, :zip, :county, :phone, :email, :website, neighborhood_ids: [], category_ids: [])
end
specifically, I'm not sure how this part is supposed to write:
category_ids: []
I'll be trying out different stuff until I figure out how to persist it. As it is, I'll pass in those params and nothing gets saved, so I figure I need to explicitly state [:0, :1, :2] but I'm not actually sure how to do that, or that this is the right solution
edit:
new params look like this
"category_ids"=>{"one"=>"53029921d2b38bf8da000006", "two"=>"53029921d2b38bf8da00001b", "three"=>"53029921d2b38bf8da000004"}
The actual html in the form was goofing me up here. Solved!
Upvotes: 0
Views: 71
Reputation: 962
params.require(:program).permit(:name, :slug, :description, :cost, :min_age, :max_age, :how_to_access, :min_grade, :max_grade, :start_date, :end_date, :notes, :tag_list, :eligibility, :street_address, :state, :city, :zip, :county, :phone, :email, :website, neighborhood_ids: [], category_ids: ['1','2', '3'])
You cannot convert nos into a symbol.
Upvotes: 2