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 8679011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:51:56+00:00 2026-06-12T20:51:56+00:00

I’m trying to create an application with backbone, on the client side, and Rails

  • 0

I’m trying to create an application with backbone, on the client side, and Rails on the server side. It works but I have a problem on create, update and destroy.

I’m doing this :

m = new MyFirstProjectServer.Models.Inquiry({id: 1})
m.fetch() #work fine
m.set({title: 'title', description: 'description'}) 
m.save() #don't work

An ajax call is done on save :

Access-Control-Allow-Head...    X-Requested-With, X-Prototype-Version
Access-Control-Allow-Meth...    POST, GET, OPTIONS, PUT
Access-Control-Allow-Orig...    *
Access-Control-Max-Age  1728000
Cache-Control   no-cache
Connection  Keep-Alive
Content-Length  0
Content-Type    text/plain; charset=utf-8
Date    Sat, 13 Oct 2012 22:27:33 GMT
Server  WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)
X-Request-Id    a5b58b91a95b72f30849d39db0f0358f
X-Runtime   0.002259
x-ua-compatible IE=Edge
Requêtevoir le code source
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Access-Control-Request-He...    content-type
Access-Control-Request-Me...    PUT
Connection  keep-alive
Host    192.168.20.101:3000
Origin  http://localhost:4567
User-Agent  Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:16.0) Gecko/20100101 Firefox/16.0

The request is handled on the server side :

Started OPTIONS "/inquiries/2" for 192.168.20.101 at 2012-10-13 18:27:33 -0400
Processing by InquiriesController#options as HTML
  Parameters: {"id"=>"2"}
  Rendered text template (0.0ms)
Completed 200 OK in 0ms (Views: 0.3ms | ActiveRecord: 0.0ms)

Finaly, it thrown this error on save callback :

readyState 0
responseText ""
status 0
statusText "error"

This is my controller :

class InquiriesController < ApplicationController
  ...
  def show
    render json: Inquiry.find(params[:id])
  end

  def create
    @inquiry = Inquiry.new(params[:inquiry])
    if @inquiry.save
      render json: @inquiry, status: :created, location: @inquiry
    else
      render json: @inquiry.errors, status: :unprocessable_entity
    end
  end
  ...

  def options
    headers['Access-Control-Allow-Origin'] = '*'
    headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS, PUT. DELETE'
    headers['Access-Control-Allow-Headers'] = 'X-Requested-With, X-Prototype-Version'
    headers['Access-Control-Max-Age'] = '1728000'
    render :text => '', :content_type => 'text/plain'
  end
end

I have this on the ApplicationController :

class ApplicationController < ActionController::Base
  after_filter :cors_set_access_control_headers

  protected
  def cors_set_access_control_headers
    headers['Access-Control-Allow-Origin'] = '*'
    headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS, PUT'
    headers['Access-Control-Max-Age'] = "1728000"
  end
end

This is my routes :

MyFirstProjectServer::Application.routes.draw do
  get "main/index"
  root to: "main#index"

  resources :inquiries
  match '/inquiries', controller: :inquiries, action: :options, constraints: {method: 'OPTIONS'}
  match '/inquiry', controller: :inquiries, action: :options, constraints: {method: 'OPTIONS'}
  match '/inquiry/:id', controller: :inquiries, action: :options, constraints: {method: 'OPTIONS'}
  match '/inquiries/:id', controller: :inquiries, action: :options, constraints: {method: 'OPTIONS'}
end

And finaly, this is my model :

class MyFirstProjectServer.Models.Inquiry extends Backbone.Model
  urlRoot:"http://192.168.20.101:3000/inquiries/"

Do you have a solution?

Thanks!

  • 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-12T20:51:58+00:00Added an answer on June 12, 2026 at 8:51 pm

    The solution was realy simple.

    I changed this :

    headers['Access-Control-Allow-Headers'] = 'X-Requested-With, X-Prototype-Version'
    

    For this :

    headers['Access-Control-Allow-Headers'] = 'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.