jeudi 3 décembre 2015

Rails 4 Checkboxes: Not getting saved to database

I'm using Rails 4 and I have 3 models: property, category, and categorization.

The application is here: http://ift.tt/21yvEo3

The idea: you can update a property and there's 6 categories (6 checkboxes) to choose from.

I came across this SO post and it was helpful but alas, my values still aren't getting saved.

When I click the update button to update a property: the server logs (if I select checkboxes 3 4 and 5) will be:

**Processing by PropertiesController#update as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"Dcgy+3qBF4JLeu5MMATyqOc+jWyILXTfgURbqn+Ez8E2ru3rpzgPBqKDPWsy/QelQuQgOczdC8xDsOnnwSDAnQ==", "property"=>{"name"=>"Vizcaya", "category_id"=>["3", "4", "5", ""]}, "commit"=>"Update Property", "id"=>"6"}**

If I fire up rails console and check out the ^above property, category_id is set to nil. Why is this? My strong params are correct in the properties_controller I think:

def property_params
  params.require(:property).permit(:name, :category_id => [])
end

Any and all input is greatly appreciated.




Aucun commentaire:

Enregistrer un commentaire