11
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

rails-backbone gemを使ってとりあえず単ページJS CRUDアプリケーションを作ってみる

Last updated at Posted at 2013-04-01

今回はRubyMineを使うが、それ以外の場合もほぼ同じだろう。

  1. rails applicationを作る

アプリケーション名があとで必要になる。

  1. コードを書く
Gemfile
gem "rails-backbone"
  1. bundle install

  2. Tools > Run Rails Script > rails, g backbone:install

  3. app/assets/javascripts/backbone/に以下のフォルダができる

routers/
models/
templates/
views/
  1. Tools > Run Rails Generator > scaffold > Post title:string content:string

  2. Tools > Run Rails Script > rails, g backbone:model

app/assets/javascript/backbone/modelsにBackboneのモデルとコレクションができる。

  1. Tools > Run Rake Task > db:migrate

  2. Tools > Run Rails Script > rails, g backbone:scaffold Post title:string content:string

  3. コードを書く

Blogの部分をアプリケーション名で置き換えること。

app/views/index.html.erb
<div id="posts"></div>

<script type="text/javascript">
    $(function() {
        // Blog is the app name
        window.router = new Blog.Routers.PostsRouter({posts: <%= @posts.to_json.html_safe -%>});
        Backbone.history.start();
    });
</script>
  1. Run > Run 'Development'

  2. ブラウザで見ると、単ページ・アプリケーションができている


ブログやってます:PAPA-tronix !

11
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?