https://github.com/westonplatter/railsy_backbone
Use https://github.com/codebrew/backbone-rails
https://github.com/westonplatter/railsy_backbone
Last synced: about 2 months ago
JSON representation
Use https://github.com/codebrew/backbone-rails
- Host: GitHub
- URL: https://github.com/westonplatter/railsy_backbone
- Owner: westonplatter
- License: other
- Created: 2013-07-31T17:48:08.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2014-08-05T17:53:51.000Z (almost 11 years ago)
- Last Synced: 2024-04-30T21:12:46.163Z (about 1 year ago)
- Language: Ruby
- Homepage:
- Size: 597 KB
- Stars: 9
- Watchers: 3
- Forks: 6
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Please Use [codebrew/backbone-rails](https://github.com/codebrew/backbone-rails)
This repo is no longer maintained since the backbone-rails repo is now receiving updates.
# railsy_backbone
[](http://badge.fury.io/rb/railsy_backbone) [](https://travis-ci.org/westonplatter/railsy_backbone)
A clone of [codebrew/backbone-rails](https://github.com/codebrew/backbone-rails) with updated Backbone, Underscore, and jquery-rails versions.
Provides Backbone & Underscore files and modifies Backbone to:
- include the Rails authenticity token in HTTP requests
- nest model attributes within the declared `paramRoot` , EG,```js
var Book = Backbone.Model.extend({
url: '/books',
paramRoot: 'book'
});var book_instance = new Book({
title: 'the illiad',
author: 'homer'
});book_instance.sync();
```This will cause the resulting HTTP POST to be,
```sh
Started POST "/books" for 127.0.0.1 ...
Processing by BooksController#create as JSON
Parameters: { "book" => { "title" => "the illiad", "author" => "homer", "id" => 1 } }
```## Example App
https://github.com/westonplatter/example_railsy_backbone
## Branches
master
- Backbone 1.1.0
- Underscore 1.5.21-0-stable
- Backbone 1.0.0
- Underscore 1.5.1## Rails Setup
### Install
Add this line to Gemfile,
gem 'railsy_backbone'
And then,
$ bundle install
$ rails g backbone:install
This requires Backbone, Underscore, and the Backbone modifications to implement
the Rails authenticity token and nesting model attributes in the paramsRoot
(see Javscript files with the `railsy_backbone.` prefix for details).These will be added to your `app/assets/javascripts/application.js`:
//= require jquery
//= require jquery_ujs
//= require underscore
//= require backbone
//= require railsy_backbone.sync
//= require railsy_backbone.datalink
//= require backbone/
//= require_tree .### Generators
Backbone Model `$ rails g backbone:model`
Backbone Router `$ rails g backbone:router`
Backbone Scaffold `$ rails g backbone:scaffold`### Example Usage
Create new rails app,
rails new library
cd libraryInstall `railsy_backbone`,
# add railsy_backbone to Gemfile
bundle install
rails g backbone:installGenerate a standard Rails scaffold,
rails g scaffold Book title:string author:string
rake db:migrateGenerate a `Backbone` scaffold,
rails g backbone:scaffold Book title:string author:string
Edit `books/index.html` to execute actions through the Backbone scaffold UI rather than routing to different pages.
If you're using ERB, `index.html.erb`
$(function() {
window.router = new Library.Routers.BooksRouter({books: <%= @books.to_json.html_safe -%>});
Backbone.history.start();
});
Or HAML, `index.html.haml`
#books
:javascript
$(function() {
window.router = new Library.Routers.BooksRouter({books: #{@books.to_json.html_safe}});
Backbone.history.start();
});If you're using the default Rails 4 scaffold generators, you'll need to adjust
the default JSON show view (IE, `show.json`) to render the `id` attribute.# BROKEN -- default rails generated show.json.jbuilder
json.extract! @book, :title, :author, :created_at, :updated_at# FIXED --- after adding `id`
json.extract! @book, :id, :title, :author, :created_at, :updated_atWithout adjusting the JSON show view, you will be redirected to a "undefined"
url after creating an object.## Docs
[Link to the docs](http://westonplatter.github.io/railsy_backbone/).I value clear communication __(I'm serious!)__. If you think something is missing in the docs, __please__ open a GitHub issue ([create issues here](https://github.com/westonplatter/railsy_backbone/issues)), and I'd love to add it if it makes sense.
## Contributors
[These awesome people](https://github.com/westonplatter/railsy_backbone/graphs/contributors) infused their awesome talent in this project.## Credits
Inspired by and copied from Ryan Fitzgerald's [codebrew/backbone-rails](https://github.com/codebrew/backbone-rails).## License
See LICENSE[](https://bitdeli.com/free "Bitdeli Badge")