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

  • Home
  • SEARCH
  • 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 9117977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:01:39+00:00 2026-06-17T05:01:39+00:00

I have a rails app using backbone. In the console, I can create a

  • 0

I have a rails app using backbone. In the console, I can create a collection, fetch documents from the server (3) which I confirm by checking length

docs = new Docs();
docs.fetch();
docs.length
3

get one of those docs

d1 = docs.at(0)
Object { cid=
“c3”
, changed={…}, attributes={…}, more…}

destroy the doc

d1.destroy();
DELETE http: localhost:3000/docs/1
204 No Content 23ms
jquery.js?body=1 (line 8215)
Object { readyState=
1
, setRequestHeader=function(), getAllResponseHeaders=function(), more…}

check the length of docs

>>> docs.length

2

Create a new collection

docz = new Docs();

get the documents from the server. Note the “304 Not modified message”

docz.fetch();
GET http:// localhost:3000/docs
304 Not Modified
31ms
jquery.js?body=1 (line 8215)
Object { readyState=
1
, setRequestHeader=function(), getAllResponseHeaders=function(), more…}

Check the length. It’s 3, when I expected it to be 2.

>>> docz.length

3

I don’t know why when I call destroy I’m getting a no content message if there’s clearly 3 records

204 No Content
        23ms

When I retrieve a record from the database, I have no problem accessing data

d.get('title')
>>>"diet book"

I have a url set on the model, so I should be able to delete individual records I’d think

   url : function() {
       var base = 'docs';
       if (this.isNew()) return base;
       return base + (base.charAt(base.length - 1) == '/' ? '' : '/') + this.id;
    },

However, I also can’t delete going through a collection docs.at(0).destroy has the same effect.

This is my destroy function in the rails controller

class DocsController < ApplicationController


    respond_to :json
    ....

   def destroy
     respond_with Doc.find(params[:id])
   end 
end 

The model

 class Doc < ActiveRecord::Base
  attr_accessible :keywords, :text, :title
 end

Update
One person who commented on this post noted that I’m supposed to destroy something when I call destroy, but I thought calling destroy on the object destroyed the object

d.destroy()  #should destroy d, shouldn't it?

This is what I understood from the docs

 book.destroy({success: function(model, response) {
  ...
}});

Indeed, when I call save() on an object, it saves the object to the database

d.save(); #this works, so why not d.destroy();
  • 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-06-17T05:01:40+00:00Added an answer on June 17, 2026 at 5:01 am

    When you do this in your Backbone code:

    d.destroy();
    

    you’ll trigger a DESTROY request to the server and the client-side model will be destroyed and cleaned up. Your server code will have to deal with the DESTROY request by destroying the server-side model; your destroy controller doesn’t do that:

    def destroy
      respond_with Doc.find(params[:id])
    end
    

    All that does is pull the appropriate Doc out of the database and sends it back to the client: your destroy controller needs to destroy the server-side model. You need to adjust your controller method to include:

    doc = Doc.find(params[:id])
    doc.destroy
    

    A bit of permission checking, error checking, and exception handling on the find and destroy calls might be a good idea too.

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

Sidebar

Related Questions

I have a rails app using backbone, but when I call save, the server
I have a Rails 3.2.3 app with Backbone.js and I'm using pushState on my
I have a Rails 3 App using devise. I want to create a User/Profile
I have Rails app set up using Jruby with puma as the web server.
I have an app using Rails 3.0.6 which I run on two machines. I
I'm using codebrew\backbone-rails in a nested model example (say I have a collection of
I have a web app which is part Rails and part Backbone . Some
I have a rails app that is using Devise perfectly in development. I have
I have a rails app set up as an OAuth2 provider (using Doorkeeper). The
I have a Rails app that is served by Apache and Passenger, using only

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.