author avatar

syedsibtain

Thu May 09 2024

In Rails, the resources method provides a convenient way to define RESTful routes for our application's resources. Instead of manually specifying separate routes for each CRUD action (Create, Read, Update, Delete), we can use the resources method to define all these routes with a single line of code.



# config/routes.rb

Rails.application.routes.draw do
  resources :students
end


With this single line of code, Rails automatically generates the following RESTful routes for the students resource:



GET     /students          # Index action (display a list of students)
GET     /students/new      # New action (display a form to create a new student)
POST    /students          # Create action (create a new student)
GET     /students/:id      # Show action (display details of a specific student)
GET     /students/:id/edit # Edit action (display a form to edit a specific student)
PATCH   /students/:id      # Update action (update a specific student)
PUT     /students/:id      # Update action (update a specific student)
DELETE  /students/:id      # Destroy action (delete a specific student)


#rails #routes