#author("2017-03-13T10:29:51+09:00","default:wikiwriter","wikiwriter")
&tag(Rails/プラグイン/チュートリアル);
*目次 [#r8006278]
#contents

*関連ページ [#k731fe49]
-[[Rails/プラグイン]]

*参考情報 [#beef44fa]
-https://railsguides.jp/engines.html

*作成 [#l98d448e]

**mountable型の作成 [#h0335811]
***プロジェクトの作成 [#k3f40a79]
-以下のコマンドを実行
 bundle exec rails plugin new ~/work/blorgh --mountable --skip-bundle
-blorgh.gemspecを編集してTODOを削除したあと、bundle installの実行
  bundle install --path=vendor/bundle

***Articleリソースの作成 [#d01f6ff6]
-以下のコマンドを実行
 bundle exec bin/rails generate scaffold article title:string text:text
-モデルやコントローラーにネームスペースが付与されていることに注意。
#pre{{
$ bundle exec bin/rails generate scaffold article title:string text:text
      invoke  active_record
      create    db/migrate/20161025072006_create_blorgh_articles.rb
      create    app/models/blorgh/article.rb
      invoke    test_unit
      create      test/models/blorgh/article_test.rb
      create      test/fixtures/blorgh/articles.yml
      invoke  resource_route
       route    resources :articles
      invoke  scaffold_controller
      create    app/controllers/blorgh/articles_controller.rb
      invoke    erb
      create      app/views/blorgh/articles
      create      app/views/blorgh/articles/index.html.erb
      create      app/views/blorgh/articles/edit.html.erb
      create      app/views/blorgh/articles/show.html.erb
      create      app/views/blorgh/articles/new.html.erb
      create      app/views/blorgh/articles/_form.html.erb
      invoke    test_unit
      create      test/controllers/blorgh/articles_controller_test.rb
      invoke    helper
      create      app/helpers/blorgh/articles_helper.rb
      invoke      test_unit
      invoke  assets
      invoke    js
      create      app/assets/javascripts/blorgh/articles.js
      invoke    css
      create      app/assets/stylesheets/blorgh/articles.css
      invoke  css
      create    app/assets/stylesheets/scaffold.css
}}
-miration実行
 bundle exec rake db:migrate
-test/dummyディレクトリで実行。http://localhost:3000/blorgh/articlesでアクセスできる。
 bundle exec rails s

***Commentリソースの生成 [#t6b759ed]
-記事1に対して複数のコメントがつけられる。
-以下のコマンドを実行。
#pre{{
$ bundle exec bin/rails generate model Comment article_id:integer text:text
      invoke  active_record
      create    db/migrate/20161025073042_create_blorgh_comments.rb
      create    app/models/blorgh/comment.rb
      invoke    test_unit
      create      test/models/blorgh/comment_test.rb
      create      test/fixtures/blorgh/comments.yml
}}
-migration実行
 bundle exec rake db:migrate
-以下の概略。app/views/blorgh/articles/show.html.erbにコメント一覧とコメント追加用のフォームを追加する。


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS