Challenge - 5 Problems
Rails Controller Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the default action created by
rails generate controller?You run
rails generate controller Products. Which action is created by default in the generated controller?Attempts:
2 left
💡 Hint
Think about what happens if you don't specify any actions when generating a controller.
✗ Incorrect
When you run rails generate controller Products without specifying actions, Rails creates the controller file with no actions inside. You must explicitly list actions to generate them.
📝 Syntax
intermediate2:00remaining
Which command generates a controller with
index and show actions?Select the correct Rails command to generate a controller named
Articles with index and show actions.Attempts:
2 left
💡 Hint
Check the official Rails generator syntax for specifying actions.
✗ Incorrect
The correct syntax is to list the actions after the controller name separated by spaces. Options like --actions or -a are not valid.
❓ state_output
advanced2:00remaining
What files are created by
rails generate controller Users new edit?After running
rails generate controller Users new edit, which of the following files is NOT created?Attempts:
2 left
💡 Hint
Consider what the controller generator creates versus the model generator.
✗ Incorrect
The controller generator creates the controller file and view templates for the specified actions. It does not create model files.
🔧 Debug
advanced2:00remaining
Why does
rails generate controller Posts show fail with uninitialized constant PostsController error?You ran
rails generate controller Posts show but when visiting /posts/show you get uninitialized constant PostsController. What is the most likely cause?Attempts:
2 left
💡 Hint
The error means Rails cannot find the controller class at all.
✗ Incorrect
uninitialized constant PostsController means Rails cannot find the controller class. This usually happens if the controller file was not created or saved correctly.
🧠 Conceptual
expert2:00remaining
What is the effect of adding
--skip-routes when generating a controller?You run
rails generate controller Comments index --skip-routes. What is the effect of the --skip-routes option?Attempts:
2 left
💡 Hint
Think about what Rails normally does with routes when generating a controller.
✗ Incorrect
By default, Rails adds a route for each generated action. The --skip-routes option prevents this automatic route creation.