-
Notifications
You must be signed in to change notification settings - Fork 0
Home
aizawa1126 edited this page Jul 26, 2012
·
1 revision
rails new BackboneSample
cd BackboneSample
vi Gemfile
gem 'rails-backbone'
bundle install
rails g scaffold Post title:string content:string
rake db:migrate
rails g backbone:install
rails g backbone:scaffold Post title:string content:string
vi app/views/posts/index.html.erb
<div id="posts"></div> <script type="text/javascript"> $(function() { // BackboneSample is the app name window.router = new BackboneSample.Routers.PostsRouter({posts: <%= @posts.to_json.html_safe -%>}); Backbone.history.start(); }); </script>
#Rails側で更新不可能に設定したカラムを、Backboneが更新しようとしてエラーになっているため、更新カラムをカスタマイズする。
vi app/assets/javascripts/backbone/views/posts/edit_view.js.coffee
id = @model.attributes.id title = @model.attributes.title content = @model.attributes.content @model.attributes={id: id, title: title, content: content}
rails s