Ruby on Rails

Routing & Controllers

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

22 gespreksvragen·
Junior
1

In a Rails application, where is the main route configuration file located?

Antwoord

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?

Antwoord

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?

Antwoord

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 gespreksvragen

Beheers Ruby on Rails voor je volgende gesprek

Krijg toegang tot alle vragen, flashcards, technische tests, code review-oefeningen en gespreksimulatoren.

Begin gratis