0
votes

I'm trying to use a Backbone.js model to keep track of what guides a user has seen. I would like to store the value in User.guides which is a serialized field in rails.

var Model = Backbone.Model.extend({
    urlRoot : '/users',
    defaults : {
        user : {
            guides : {
                step1 : false,
                step2 : false           
            }           
        }
    }

});

That's what happens on load. Later on when I try to make an update:

me.model.set({
    user : {
        room_wizard : {
            project_completed : true
        }           
    }
});


me.model.save();

The problem here is Rails is erroring for the following reasons:

  • Backbone.js is posting to create as JS when it should be Update as JSON? Why?

Ideas? Am I handling the above incorrectly? I'm new to backbone.js Thanks

1
The issue might be that with rails + devise, to update current user's user model, you post to /users instead of /users/:id --- Is there a way to handle this ? - AnApprentice

1 Answers

2
votes

The Backbone's rule of thumb for choosing between POST or PUT to the server is if the Model has an id or has not.

  • If Model has an id Backbone will use the verb PUT.
  • If Model has not an id Backbone will use the verb POST.