Rails Generate Controller

suggest change

we can create a new controller with rails g controller command.

$ bin/rails generate controller controller_name

The controller generator is expecting parameters in the form of generate controller ControllerName action1 action2.

The following creates a Greetings controller with an action of hello.

$ bin/rails generate controller Greetings hello

You will see the following output

create  app/controllers/greetings_controller.rb
 route  get "greetings/hello"
invoke  erb
create    app/views/greetings
create    app/views/greetings/hello.html.erb
invoke  test_unit
create    test/controllers/greetings_controller_test.rb
invoke  helper
create    app/helpers/greetings_helper.rb
invoke  assets
invoke    coffee
create      app/assets/javascripts/greetings.coffee
invoke    scss
create      app/assets/stylesheets/greetings.scss

This generates the following

File | Example | —— | —— | Controller File | greetings_controller.rb | View File | hello.html.erb | Functional Test File | greetings_controller_test.rb | View Helper | greetings_helper.rb | JavaScript File | greetings.coffee |

It will also add routes for each action in routes.rb

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents