I have a Rails application with the backbone-rails gem. Which works out fine but Backbone tries to send a request with all the attributes of the model. Is there a way I can filter out some of the attributes that will be POST’d on an update/new? This would work great for those virtual attributes and attributes that can’t be mass assigned.
Share
There is no harm in posting attributes that cannot be mass assigned. You will see a warning, but everything will work.
There are basically two ways of actually removing unwanted attributes. The first is to customize the Model’s
toJSON(). For example:The second, and less clean way, is to explicitly pass the data in your call to
Model.save(). If you are using the defaultBackbone.sync()method, then this data will be used instead. For example:You can probably figure out a way to generalize either of those approaches, depending on which one works for you.