Pages

Thursday, May 2, 2013

What is RESTful routing?

Routing is fun. If you have ever dealt with IIS you will fall in love with RESTful routing. Here’s how it works.
Say you want your users to have access to certain pages such as:
/photos/new
/photos/1/edit
/photos/1
And, you want the right controller to get called.
And, you want the right view to get rendered.
All this is made possible with a single entry in the routes.rb file as shown below:
resources :photos 
In Rails, a resourceful route provides a mapping between HTTP verbs and URLs to controller actions. By convention, each action also maps to particular CRUD operations in a database. The single entry in the routing file creates seven different routes in your application, all mapping to the Photos controller:

No comments:

Post a Comment