Learning Rails – Routing
Posted on: Wednesday, May 21, 2014
Starting the second course, Rapid Prototyping with Ruby on Rails, over at the Tealeaf Academy, I’m starting to learn how to work with Rails.
One of the subjects in this lesson of study material is Rails’s Routing documentation.
In the Rails Routing guide the 7 different routes are explained that are automatically created when specifying a plural resource in routes.rb
.
For example, resources :objects:
-
Collection actions
ObjectsController#index
HTTP: GET
Path: /objects  –>Âobjects_path
ObjectsController#new
HTTP: GET
Path: /objects/new –>new_object_path
ObjectsController#create
HTTP: POST
Path: /objects
-
Member actions
ObjectsController#show
HTTP: GET
Path: /objects/:id –>object_path(:id)
ObjectsController#edit
HTTP: GET
Path: /objects/:id/edit –>edit_object_path(:id)
ObjectsController#update
HTTP: PATCH / PUT
Path: /objects/:idObjectsController#destroy
HTTP: DELETE
Path: /objects/:id
As you’re going to encounter these very often, it’s important to remember them!
If you specify a singular resource, the index route is not available. The other routes basically only work without an id:
-
Member actions
ObjectsController#new
HTTP: GET
Path: /object/new –>new_object_path
ObjectsController#create
HTTP: POST
Path: /objectObjectsController#show
HTTP: GET
Path: /object –>object_path
ObjectsController#edit
HTTP: GET
Path: /objects/edit –>edit_object_path
ObjectsController#update
HTTP: PATCH / PUT
Path: /objectObjectsController#destroy
HTTP: DELETE
Path: /object
The possibilities of Rails routing are plentiful. Head over to the guide Rails Routing from the Outside In to continue reading.
Alif
June 22nd, 2015 at 00:20
Permalink this comment
1
Please like to know about tealeaf academy i am very new in programming language i just start learn ruby this is my 1st language i start learn please can i talk with little bit please live chat or Facebook thank advance for you kind and valuable time thanks
Codefish
September 25th, 2015 at 10:40
Permalink this comment
2
Hello Alif,
You can find all information about the course I’m following at http://www.gotealeaf.com/.
As you can read, I certainly recommend taking up the course(s) there.
Good luck!