Reputation: 33
i am new to ruby on rails.
Can anyone please explain about routes in ruby on rails.
example:
match 'dash_bw' :to 'reports#dash_bw'
How it link to controller,can please explain.
'report#dash_bw'
Here we writing class name that define in controller, is it write ?
If it wrong please explain how it link to controller and view.
please don't mind i am learning, my own please explain .
right side of routes match is class name or directory name.
Thanks!
Upvotes: 0
Views: 93
Reputation: 53018
First of all, the route should look like:
match 'dash_bw', to: 'reports#dash_bw', via: :get
which will create a route like
dash_bw GET /dash_bw(.:format) reports#dash_bw
You can check the routes by running rake routes
command.
When you access http://yourdomain.com/dash_bw
in the browser which will call dash_bw
action in your ReportsController
(because of reports#dash_bw).
Also, you could also use the new way to define the routes as:
get 'dash_bw', to: 'reports#dash_bw', as: :dash_bw
Here we writing class name that define in controller, is it write ?
To answer the above question, you specify the class name of the controller, but not the complete name just the prefix part before the Controller
.
For example: if your controller name is ReportsController
then you specify reports
(in lower case) in your to:
option i.e., to: reports#dash_bw
part. Please note that dash_bw
is your action
name.
Upvotes: 5
Reputation: 106
'reports#dash_bw'
refers to Reports Controller, dash_bw Action.
You must have a controller like:
class ReportsController...
def dash_bw
... code here
end
end
So when the browser hits that route what ends up happening is the dash_bw method gets called.
Upvotes: 0