28
24

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 generate を dry run (お試し実行) したい

Posted at

Rails の rails generate (あるいは rails g) コマンドって、
自動的に必要なファイルを作ってくれるから便利ですよね。
ただ、このコマンドを実行することでどんなファイルが作成されるのか、
実行前に知りたいときもありますよね。

たまにゴミファイル群を作っちゃって、あたしって、ほんとバカ…

そんなときは -p (あるいは --pretend) オプションを使うことで、
実際にファイルを生成することなく、実行結果の確認ができます。

$ git status # 作業ツリーが空っぽであることを確認
# On branch develop
nothing to commit (working directory clean)

$ bundle exec rails g scaffold Magica -p
      invoke  active_record
      create    db/migrate/20130614153139_create_magicas.rb
      create    app/models/magica.rb
      invoke    rspec
      create      spec/models/magica_spec.rb
      invoke      factory_girl
      create        spec/factories/magicas.rb
      invoke  resource_route
       route    resources :magicas
      invoke  scaffold_controller
      create    app/controllers/magicas_controller.rb
      invoke    haml
      create      app/views/magicas
      create      app/views/magicas/index.html.haml
      create      app/views/magicas/edit.html.haml
      create      app/views/magicas/show.html.haml
      create      app/views/magicas/new.html.haml
      create      app/views/magicas/_form.html.haml
      invoke    rspec
      create      spec/controllers/magicas_controller_spec.rb
      create      spec/views/magicas/edit.html.haml_spec.rb
      create      spec/views/magicas/index.html.haml_spec.rb
      create      spec/views/magicas/new.html.haml_spec.rb
      create      spec/views/magicas/show.html.haml_spec.rb
      create      spec/routing/magicas_routing_spec.rb
      invoke      rspec
      create        spec/requests/magicas_spec.rb
      invoke    helper
      create      app/helpers/magicas_helper.rb
      invoke      rspec
      create        spec/helpers/magicas_helper_spec.rb
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/magicas.js.coffee
      invoke    scss
      create      app/assets/stylesheets/magicas.css.scss
      invoke  scss
      create    app/assets/stylesheets/scaffolds.css.scss

$ git status # generate 後も作業ツリーは空っぽのままだ
# On branch develop
nothing to commit (working directory clean)

自分は最近まで知りませんでした…
やっぱり定期的に使うコマンドは、一度 help に目を通しておかないと行けませんね。

28
24
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
28
24

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?