user2371769
user2371769

Reputation: 47

ruby rails how to get path to named route

How to get the path helper for a named route?

routes.rb

match 'report/monitor_id/:monitor_id/week_ending_date/:week_ending_date' => 'report#index'

How do I get the path helper for a named route? when I do rake routes, there's nothing in front

/report/monitor_id/:monitor_id/week_ending_date/:week_ending_date(.:format)        report#index

Is there a way to get report_monitor_id_week_ending_date_path(monitor_id, week_ending_date)?

Upvotes: 2

Views: 3969

Answers (1)

jefflunt
jefflunt

Reputation: 33954

You can give it a name with the :as parameter:

http://guides.rubyonrails.org/routing.html#naming-routes

Ex:

match 'exit' => 'sessions#destroy', :as => :logout

Which should provide the helpers:

logout_path
logout_url

Not sure what you want your route to be named, but maybe something like:

match 'report/monitor_id/:monitor_id/week_ending_date/:week_ending_date' => 'report#index', :as => :weekly_monitor_report

Which I believe will give you the helpers that allow passing the parameters in the order they are specified in the route definition:

weekly_monitor_report_path(:monitor_id, :week_ending_date)
weekly_monitor_report_url(:monitor_id, :week_ending_date)

Upvotes: 6

Related Questions