81
76

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.

Ruby on RailsAdvent Calendar 2013

Day 25

よく使うscaffoldコマンドのオプション

Last updated at Posted at 2013-12-25

前提

Railsアプリケーション自体は

rails new App -T

でTest::Unitをスキップして作成して、代わりにrspecfactory-girlを入れた状態を想定。

Gemfile
gem 'rspec-rails'
gem 'factory_girl_rails'

railsのバージョンは3.2でも4.0系列でも試している。

使用コマンド

$ rails g scaffold ModelName user:references name description:text amount:integer weight:float active:boolean born_on:date deleted_at:datetime --skip-assets --skip-helper --skip-stylesheets --skip-view-specs --skip-controller-specs --skip-routing-specs --skip-request-specs

jbuilderがいらない場合は以下も

 --skip-jbuilder

方針

  • Model, View, Controller, Routeは追加
  • Javascript, CSS用のファイルは無駄に作らない
  • Helperも大抵いらないので作らない
  • テストに関してはModelのテストだけを作ってもらう

controller-specsに関してはskipしなくてもいいかと思うけど、他のテストは本当に必要なときに自分で作ったんでいいと思う。・・・実際。

結果

rails3.2
      invoke  active_record
      create    db/migrate/20131225083227_create_model_names.rb
      create    app/models/model_name.rb
      invoke    rspec
      create      spec/models/model_name_spec.rb
      invoke      factory_girl
      create        spec/factories/model_names.rb
      invoke  resource_route
       route    resources :model_names
      invoke  scaffold_controller
      create    app/controllers/model_names_controller.rb
      invoke    erb
      create      app/views/model_names
      create      app/views/model_names/index.html.erb
      create      app/views/model_names/edit.html.erb
      create      app/views/model_names/show.html.erb
      create      app/views/model_names/new.html.erb
      create      app/views/model_names/_form.html.erb
      invoke    rspec
      invoke      rspec
      invoke  scss
rails4.0
      invoke  active_record
      create    db/migrate/20131225082800_create_model_names.rb
      create    app/models/model_name.rb
      invoke    rspec
      create      spec/models/model_name_spec.rb
      invoke      factory_girl
      create        spec/factories/model_names.rb
      invoke  resource_route
       route    resources :model_names
      invoke  scaffold_controller
      create    app/controllers/model_names_controller.rb
      invoke    erb
      create      app/views/model_names
      create      app/views/model_names/index.html.erb
      create      app/views/model_names/edit.html.erb
      create      app/views/model_names/show.html.erb
      create      app/views/model_names/new.html.erb
      create      app/views/model_names/_form.html.erb
      invoke    rspec
      invoke      rspec
      invoke    jbuilder
      create      app/views/model_names/index.json.jbuilder
      create      app/views/model_names/show.json.jbuilder
81
76
1

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
81
76

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?