Search code examples
ruby-on-railsember.jsruby-on-rails-4strong-parameters

Posting parent_id in Ember.js and Rails 4 causes unpermitted parameters error. Remove or ignore?


In ember.js (1.2) I am trying to POST a change to a child model but ember.js is including the parent_id in the POST. The parent_id is not a "permitted" parameter for my Rails 4 controller, however, so the POST fails with the following error.

Processing by ThingsController#update as JSON
  Parameters: {"thing"=>{"title"=>"Test","location"=>"Baltimore","parent_id"=>nil}
Unpermitted parameters: parent_id

Since I don't want to make parent_id a permitted parameter for this model, how to I remove it from the POST?


Solution

  • I was able to resolve this by removing the reference to parent in the child class. This turned out to not be necessary in my application since I often access children from the parent, but I never access the parent from the child. In other words, the new model looks something like:

    App.Thing = DS.Model.extend({
    
    // commented out -> parent: DS.belongsTo('App.ParentThing'),
    
      title: DS.attr('String'),
      location: DS.attr('String')
    });