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

4 comments:

  1. It is very excellent blog and useful article thank you for sharing with us , keep posting learn more Ruby on Rails Online Training India

    ReplyDelete
  2. As a leading Top Mobile App Development Company, Appsinvo company is well known to design and build customized web and mobile app solutions for the clients. Complete integration of the mobile app and the website gives the businesses a boost not only in their growth but also in the revenue.
    Top Mobile App Development Company in Delhi
    Top Mobile App Development Company in Russia
    Mobile App Development Company in Europe

    ReplyDelete
  3. Ecommerce is a great way to promote customised products. Visit if you're looking for the best eCommerce App development company in the US.

    ReplyDelete
  4. We are best <a href="https://www.appslure.com/>Mobile App Development Company in Delhi</a>.

    ReplyDelete