Recall & Review
beginner
What is the purpose of the
routes.rb file in a Rails application?The
routes.rb file defines how URLs map to controller actions. It tells Rails what code to run when a user visits a specific web address.Click to reveal answer
beginner
How do you define a simple route that maps the URL
/home to the index action of the home controller?You write: <br>
get '/home', to: 'home#index'<br>This means when someone visits /home, Rails runs the index method in the home controller.Click to reveal answer
intermediate
What does the
resources :posts line do in routes.rb?It creates all the standard routes for a resource named
posts. This includes routes for showing, creating, editing, updating, and deleting posts automatically.Click to reveal answer
beginner
Explain the difference between
get and post in route definitions.get defines a route for retrieving data (like showing a page). post defines a route for sending data to the server (like submitting a form).Click to reveal answer
beginner
How can you set the root URL (homepage) of your Rails app in
routes.rb?Use the
root method like this:<br>root 'welcome#index'<br>This means the homepage URL / runs the index action of the welcome controller.Click to reveal answer
What does this route do?
get '/about', to: 'pages#about'✗ Incorrect
The route connects the URL /about to the about method inside the pages controller.
Which HTTP method is used to submit form data in Rails routes?
✗ Incorrect
post is used to send data to the server, like submitting forms.What does
resources :users generate?✗ Incorrect
It creates all common routes like index, show, new, edit, create, update, and destroy for users.
How do you set the homepage route in Rails?
✗ Incorrect
The
root method sets the homepage route.Which file do you edit to define routes in a Rails app?
✗ Incorrect
Routes are defined in the
config/routes.rb file.Describe how you would create a route for a 'contact' page that shows a form using the 'pages' controller and 'contact' action.
Think about how to connect a URL to a controller action using get.
You got /3 concepts.
Explain what the
resources method does in Rails routing and why it is useful.It saves time by generating many routes for common actions.
You got /3 concepts.