The routing module provides URL rewriting in native Ruby. It’s a way to redirect incoming requests to controllers and actions. It replaces the mod_rewrite rules. Best of all, Rails’ Routing works with any web server. Routes are defined in app/config/routes.rb.
Think of creating routes as drawing a map for your requests. The map tells them where to go based on some predefined pattern.
How to define a route
Rails.application.routes.draw doPattern 1 tells some request to go to one placePattern 2 tell them to go to anotherPattern 3 tell them to go to another…End
In the example above, we are creating 3 get requests:
· coupons#index will get the page with the list of all coupons.
· coupons#new will get the page that lets you create a new coupon.
· Coupons#show will get the page of a single coupon
Resource routing allows you to quickly declare all of the common routes for a given resourceful controller. Instead of declaring separate routes for your index, show, new, edit, create, update and destroy actions, a resourceful route declares them in a single line of code.
We can define routes for
profile resource as given below.