Skip to content

Instantly share code, notes, and snippets.

@gmanley
Created February 3, 2012 21:38
Show Gist options
  • Save gmanley/1732830 to your computer and use it in GitHub Desktop.
Save gmanley/1732830 to your computer and use it in GitHub Desktop.
Quick example of how to use backbone-rails
rvm use 1.9.3@rails_backbone_example --create
gem install rails
rails new rails_backbone_test --skip-bundle
cd rails_backbone_test
Add `gem 'rails-backbone'` to Gemfile
bundle
rails g backbone:install
rails g scaffold Post title:string content:string
rails g backbone:scaffold Post title:string content:string
rake db:migrate
rails server
Replace 'app/views/posts/index.html.erb' with:
<div id="posts"></div>
<script type="text/javascript">
$(function() {
// Blog is the app name
window.router = new RailsBackboneTest.Routers.PostsRouter({posts: <%= @posts.to_json.html_safe -%>});
Backbone.history.start();
});
</script>
navigate to 'http://localhost:3000'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment