0
0
Ruby on Railsframework~5 mins

Controller generation in Ruby on Rails - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of generating a controller in Rails?
A controller in Rails handles the incoming web requests, processes data, and sends responses back to the user, often by rendering views or redirecting.
Click to reveal answer
beginner
Which Rails command generates a new controller named 'Articles' with actions 'index' and 'show'?
rails generate controller Articles index show
Click to reveal answer
intermediate
What files are created when you generate a controller in Rails?
Rails creates a controller file (e.g., articles_controller.rb), view folders for each action, a helper file, and test files. Routes are not updated automatically.
Click to reveal answer
intermediate
How does Rails connect a controller action to a URL?
Rails uses routes defined in config/routes.rb to map URLs to controller actions, so when a user visits a URL, the matching controller action runs.
Click to reveal answer
beginner
True or False: Generating a controller automatically creates database tables.
False. Controllers handle requests and responses but do not create or modify database tables; that is done by models and migrations.
Click to reveal answer
Which command creates a new controller named 'Users' with an 'edit' action?
Arails generate controller Users edit
Brails new controller Users edit
Crails create controller Users edit
Drails make controller Users edit
What file does Rails create to define controller actions?
Aapp/views/controller_name/index.html.erb
Bapp/models/controller_name.rb
Cconfig/routes.rb
Dapp/controllers/controller_name_controller.rb
Which folder contains the views for a controller's actions?
Aapp/controllers/controller_name
Bapp/views/controller_name
Capp/models/controller_name
Dconfig/views/controller_name
Does generating a controller automatically add routes for its actions?
ANo, routes must be added manually or by using resourceful routing.
BYes, routes are always added automatically.
COnly if you specify the --routes option.
DYes, but only for the index action.
What is the role of a controller action in Rails?
ATo define database schema.
BTo store data in the database.
CTo process requests and prepare data for views or redirects.
DTo style the webpage.
Explain the steps and files involved when you generate a new controller in Rails.
Think about what happens behind the scenes when you run the generate command.
You got /5 concepts.
    Describe how a Rails controller connects a user's URL request to the code that runs.
    Consider the flow from URL to response.
    You got /4 concepts.