Need clarification on rails routes created when a controller is generated

15 views
Skip to first unread message

Padmahas Bn

unread,
Jul 1, 2015, 10:23:48 PM7/1/15
to rubyonra...@googlegroups.com
Hello all,

When a controller is generated, rails adds an entry in routes.rb for that controller and action like this.
get 'monthly_reciept/new'

But it don't create helper for this route as in this eg:
get    'login'   => 'sessions#login'

Using the second route, I can write "login_path" in any view to redirect to login action.

But how can I use the default generated route inside view without customizing ? Surely I cannot give monthly_receipt/new_path right? I cannot find this in rails guides and rake routes doesn't show any helper for this route because there is no one.

Thank you

Padmahas Bn

unread,
Jul 1, 2015, 10:50:32 PM7/1/15
to rubyonra...@googlegroups.com
I cannot find this in rails guides and rake routes doesn't show any helper for this route because there is no one.

Sorry.

 I copy pasted the route to the end so that I can find quickly but rake seems not to list the helper repeatedly. I found the helper monthly_receipt_new when I scrolled up

Mike

unread,
Jul 2, 2015, 6:18:01 AM7/2/15
to rubyonra...@googlegroups.com
You can always use the 'as' modifier

get 'monthly_reciept/new', as: 'new_monthly_receipt'

will give you the ability to use new_monthly_receipt_path
Reply all
Reply to author
Forward
0 new messages