Friday, May 10, 2013

Rails Generate Controller Commands

Typical Rails Generate Controller Command

Rails generate commands are great for cranking out boilerplate code that you can later go back and customize.

Here, I create a Rails Controller and associated files...


$ be rails g controller Application index static
Rails.env: (development), using rails_env: (development)
    conflict  app/controllers/application_controller.rb
Overwrite /hs/dev/find-activities/api-fa/app/controllers/application_controller.rb? (enter "h" for help) [Ynaqdh]
       force  app/controllers/application_controller.rb
       route  get "application/static"
       route  get "application/index"
      invoke  erb
      create    app/views/application
      create    app/views/application/index.html.erb
      create    app/views/application/static.html.erb
      invoke  test_unit
      create    test/functional/application_controller_test.rb
      invoke  helper
   identical    app/helpers/application_helper.rb
      invoke    test_unit
      create      test/unit/helpers/application_helper_test.rb
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/application.js.coffee
      invoke    scss
      create      app/assets/stylesheets/application.css.scss



Rails Destroy Controller Command

I decided that I did not want the test files. So, I removed all the files that were generated

$ be rails d controller Application index static
Rails.env: (development), using rails_env: (development)
      remove  app/controllers/application_controller.rb
       route  get "application/static"
       route  get "application/index"
      invoke  erb
      remove    app/views/application
      remove    app/views/application/index.html.erb
      remove    app/views/application/static.html.erb
      invoke  test_unit
      remove    test/functional/application_controller_test.rb
      invoke  helper
      remove    app/helpers/application_helper.rb
      invoke    test_unit
      remove      test/unit/helpers/application_helper_test.rb
      invoke  assets
      invoke    coffee
      remove      app/assets/javascripts/application.js.coffee
      invoke    scss
      remove      app/assets/stylesheets/application.css.scss



With No Test Files

Here, I generate the files without the test files.


$ be rails g controller Application index static  --no-test-framework
Rails.env: (development), using rails_env: (development)
      create  app/controllers/application_controller.rb
       route  get "application/static"
       route  get "application/index"
      invoke  erb
      create    app/views/application
      create    app/views/application/index.html.erb
      create    app/views/application/static.html.erb
      invoke  helper
      create    app/helpers/application_helper.rb
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/application.js.coffee
      invoke    scss
      create      app/assets/stylesheets/application.css.scss

No comments:

Post a Comment