
Routing & Controllers
RESTful routes, resources, nested routes, basic actions, params, strong parameters
1In a Rails application, where is the main route configuration file located?
In a Rails application, where is the main route configuration file located?
답변
The config/routes.rb file is the central point for defining all routes in a Rails application. This file maps incoming URLs to their corresponding controllers and actions. Rails reads this file at application startup to build the routing table that determines how each HTTP request will be handled.
2How many routes are generated by the declaration resources :articles in the routes.rb file?
How many routes are generated by the declaration resources :articles in the routes.rb file?
답변
The resources declaration automatically generates 7 standard RESTful routes: index (GET /articles), show (GET /articles/:id), new (GET /articles/new), create (POST /articles), edit (GET /articles/:id/edit), update (PATCH/PUT /articles/:id), and destroy (DELETE /articles/:id). This Rails convention significantly simplifies routing configuration for standard CRUD operations.
3Which HTTP method is used for the create action of a RESTful resource in Rails?
Which HTTP method is used for the create action of a RESTful resource in Rails?
답변
The create action uses the HTTP POST method following REST conventions. POST is used to create new resources because this method is not idempotent (calling it multiple times creates multiple resources). The form generated by the new action sends its data via POST to the controller's create action.
What is the difference between resource (singular) and resources (plural) in Rails routing?
How to limit the routes generated by resources to only include index and show?
+19 면접 질문