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?
✗ Incorrect
The correct syntax to generate a controller with actions is 'rails generate controller ControllerName action1 action2'.
What file does Rails create to define controller actions?
✗ Incorrect
Controller actions are defined inside the controller file located in app/controllers.
Which folder contains the views for a controller's actions?
✗ Incorrect
Each controller has a corresponding folder inside app/views where the views for its actions are stored.
Does generating a controller automatically add routes for its actions?
✗ Incorrect
Generating a controller does not add routes automatically; you must define routes in config/routes.rb.
What is the role of a controller action in Rails?
✗ Incorrect
Controller actions handle requests, interact with models, and decide what response to send back.
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.