Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6652347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:07:34+00:00 2026-05-26T01:07:34+00:00

I am using Backbone.js (version 0.5.3) and am having some trouble with a success

  • 0

I am using Backbone.js (version 0.5.3) and am having some trouble with a success callback when saving a model. It isn’t being run, even though the model is successfully saved on the server.

CoffeeScript:

console.log 'in switch_private'
console.log "private_entry attribute is currently #{@model.get('private_entry')}"
@model.save {'private_entry': true},
  success: ->
    console.log 'in success'

Compiled Javascript:

console.log('in switch_private');
console.log("private_entry attribute is currently " + (this.model.get('private_entry')));
return this.model.save({
  'private_entry': true
}, {
  success: function() {
    return console.log('in success');
  }
});

Console output:

in switch_private
private_entry attribute is currently false
XHR finished loading: "http://localhost:3000/entries/235".

I am returning head :ok from the update action in Ruby on Rails.

Adding the model and response arguments, so that it’s success: (model, response) ->, doesn’t make a difference. What is going wrong?

EDIT:
As per Trevor Burnham’s suggestion, I added an error callback, and it is being run. So what should I be returning from the Ruby on Rails action in order for Backbone to consider the save a success? At the moment I have head :ok

EDIT 2: Here is my updated compiled Javascript:

var this_view;
this_view = this;
return this.model.save({
  'private_entry': !(this.model.get('private_entry'))
}, {
  success: function(model, response) {
    return console.log('in success');
  },
    error: function(model, response) {
    return console.log('in error');
  }
});

Here is the PUT request:

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:07:35+00:00Added an answer on May 26, 2026 at 1:07 am

    I’ve run into this. You can’t just return head :ok and use Backbone’s default behavior. The default Backbone.Sync won’t have it.

    First of all, if you are doing it in your create action, you won’t ever know what your id is so the model won’t be able to update later (which you are doing, because of the “PUT”).

    Second, in your update action, the model won’t know that the data is truly in sync if you return head :ok so the sync fails again. But is doesn’t matter if you don’t have an id.

    Whatever the case, you need to return something in the body.

    Rails scaffolding, by default, returns head :ok upon successful update. This doesn’t jive with Backbone. To fix it, return the JSON instead:

    render json: @entity
    

    (where @entity is whatever your variable is in the action)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Backbone.js have a segmented control-type UI element for each model's view. They
I am building a js heavy app using backbone.js. One problem I've run into
Using Backbone.js I know it's highly recommended to set a model's property using the
I've just started using Backbone.js. I want to create a Collection and add some
Using online interfaces to a version control system is a nice way to have
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
pushState support was introduced with Backbone.js' version 0.5 update. From the backbone documentation :
I'm using backbone with the backbone-rails gem which does its own templating and project
We are using Backbone.js to build client-side UI that manipulates models shared by multiple
I am using backbone to build my web app. Currently I am facing an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.