0
0
Ruby on Railsframework~20 mins

Controller generation in Ruby on Rails - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Rails Controller Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2: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?
AA <code>new</code> action is created by default.
BAn <code>index</code> action is created by default.
CA <code>show</code> action is created by default.
DNo actions are created by default; you must specify them explicitly.
Attempts:
2 left
💡 Hint
Think about what happens if you don't specify any actions when generating a controller.
📝 Syntax
intermediate
2: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.
Arails generate controller Articles index show
Brails generate controller Articles --actions=index,show
Crails generate controller Articles -a index show
Drails generate controller Articles --with=index show
Attempts:
2 left
💡 Hint
Check the official Rails generator syntax for specifying actions.
state_output
advanced
2: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?
Aapp/models/user.rb
Bapp/views/users/new.html.erb
Capp/views/users/edit.html.erb
Dapp/controllers/users_controller.rb
Attempts:
2 left
💡 Hint
Consider what the controller generator creates versus the model generator.
🔧 Debug
advanced
2: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?
AThe <code>show</code> action is missing inside <code>PostsController</code>.
BThe route for <code>/posts/show</code> is missing in <code>config/routes.rb</code>.
CThe controller file was not saved or generated properly.
DThe model <code>Post</code> is not defined.
Attempts:
2 left
💡 Hint
The error means Rails cannot find the controller class at all.
🧠 Conceptual
expert
2: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?
AIt skips generating the controller file but creates views and routes.
BIt prevents Rails from adding a route for the <code>index</code> action automatically.
CIt disables generating view templates for the controller actions.
DIt skips creating the controller test files.
Attempts:
2 left
💡 Hint
Think about what Rails normally does with routes when generating a controller.