Ruby on Rails

Routing & Controllers

RESTful routes, resources, nested routes, basic actions, params, strong parameters

22 面接問題·
Junior
1

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.

2

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.

3

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.

4

What is the difference between resource (singular) and resources (plural) in Rails routing?

5

How to limit the routes generated by resources to only include index and show?

+19 面接問題

次の面接に向けてRuby on Railsをマスター

すべての問題、flashcards、技術テスト、コードレビュー演習、面接シミュレーターにアクセス。

無料で始める