Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save Backbone.js model to database

Tags:

backbone.js

I have just started exploring Backbone.js.
Upon submission of a form I would like Backbone.js to save the details to database.

How can I go about this?

like image 811
verdure Avatar asked Jul 25 '11 10:07

verdure


People also ask

How do you save in backbone?

Backbone is wonderful because it does a lot of work for you. To save our donut and secondHelping, we simply do this: myDonut. save(); mySecondHelping.

Do people still use Backbone JS?

Backbone. Backbone has been around for a long time, but it's still under steady and regular development. It's a good choice if you want a flexible JavaScript framework with a simple model for representing data and getting it into views.

Is Backbone JS frontend or backend?

Backend Synchronization BackboneJS is use with the front-end and back-end systems, allows the synchronization with the backend to provide support to RESTful APIs.

Is Backbone JS any good?

Backbone. js is an ideal choice for front-end and back-end development because it supports REST APIs that are used to keep the front-end and back-end in sync.


1 Answers

Unless you are using HTML5 local storage in the client the responsibility for saving to the database is not with backbone.js. Backbone will talk to the server via Backbone.sync using a REST type request. Effectively it will make an http POST request to save a new record or an http PUT request to update a current record.

The difference between a new record and a current record is that the :id field of the record is not set for a new record and is set for an old record.

If you want a tutorial using Ruby Rails as your backend solution then you can look at this tutorial.

http://www.jamesyu.org/2011/01/27/cloudedit-a-backbone-js-tutorial-by-example/

However you can use any backend server such as PHP, Java, Django etc as long as they meet the requirements of the REST interface that backbone.js uses.

If you overide Backbone.sync you can also get backbone.js to interface to pretty much any legacy http protocol as well.

like image 157
bradgonesurfing Avatar answered Oct 05 '22 23:10

bradgonesurfing