Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How routing works in rails

In my route file I have some route like below. What this means? I looked in rails route guide but I can not find explanation for => and foo: 'bar'

get '/clients/:status' => 'clients#index', foo: 'bar'

Please explain what this means?

like image 781
asdfkjasdfjk Avatar asked Mar 22 '23 04:03

asdfkjasdfjk


1 Answers

It means that for a HTTP GET request to a URI of pattern /clients/:status where :status is the variable parameter.

The => clients#index stands for Controller#action where controller is clients i.e. ClientsController and action is index.

The third option you have foo: 'bar' is basically other options to the route definition. Other options such as as, constraints and so on.

For example with as (which lets you name your route):

get '/clients/:status' => 'clients#index', as: :client_status

Here as: :client_status would replace your foo: 'bar'.

like image 138
vee Avatar answered Mar 23 '23 19:03

vee