Question

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?

Was it helpful?

Solution 3

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')
});

OTHER TIPS

I ran into the same thing with a createdAt attribute. It was easily solved by overriding the ApplicationSerializer (or in your case, ThingSerializer):

App.ApplicationSerializer = DS.ActiveModelSerializer.extend
  serialize: (record, options) ->
    json = @_super(record, options)
    delete json.created_at
    json

It won't cause you any problems to leave the value of parent_id in the POST parameters, so you can ignore it.

If you want to be clean about it (and not confuse other developers down the road), you should edit the form that is performing the POST and remove the form field that contains parent_id.

If you post your view code, I can held advise how to do the latter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top