0
0
Ruby on Railsframework~5 mins

Action methods in Ruby on Rails - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an action method in a Rails controller?
An action method is a public method inside a Rails controller that responds to a web request and renders a view or redirects the user.
Click to reveal answer
beginner
How does Rails know which action method to call for a URL?
Rails uses routing rules defined in config/routes.rb to map URLs to specific controller action methods.
Click to reveal answer
intermediate
What happens if an action method does not explicitly render or redirect?
Rails automatically renders a view template matching the action method name unless you specify otherwise.
Click to reveal answer
intermediate
Can private methods in a Rails controller be used as action methods?
No, only public methods can be action methods. Private or protected methods cannot be called as actions from a web request.
Click to reveal answer
advanced
Why should action methods be kept simple and focused?
Keeping action methods simple improves readability, maintainability, and helps separate concerns by moving complex logic to models or helpers.
Click to reveal answer
Which of the following is true about Rails action methods?
AThey are always private methods.
BThey must return a string.
CThey respond to web requests and render views or redirect.
DThey are defined in the model.
What file defines the URL to action method mapping in Rails?
Aconfig/routes.rb
Bapp/controllers/application_controller.rb
Capp/views/layouts/application.html.erb
Dconfig/database.yml
If an action method does not call render or redirect, what does Rails do?
ARaises an error.
BRenders a view matching the action name.
CRedirects to the home page.
DDoes nothing.
Which methods cannot be used as action methods in Rails?
APrivate and protected methods
BPublic methods
CMethods defined in helpers
DMethods in models
Why is it good practice to keep action methods simple?
ATo make the code harder to read.
BTo avoid using models.
CTo increase the number of lines in the controller.
DTo improve readability and maintainability.
Explain what an action method is in Rails and how it relates to routing and views.
Think about how a URL leads to a method that shows a page.
You got /4 concepts.
    Describe why private methods cannot be action methods and how to organize controller code effectively.
    Consider access control and code clarity.
    You got /4 concepts.