Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where's root_path or root_url?

In rails, there are a lot of helpers to direct our actions, like collections_path new_member_path edit_member_path and so on.

But where is the root? Is there a helper always points to my homepage?

like image 534
Lai Yu-Hsuan Avatar asked Sep 21 '11 17:09

Lai Yu-Hsuan


1 Answers

These helpers exist, but you have to set your root url before, in config/routes.rb:

root :to => "controller#action" 

You can use root_url and root_path afterwards.

Be warned that there's a catch when doing redirections with the _path helpers, you should use the _url ones when redirecting (see @LanguagesNamedAfterCoffee's comment for the details).

like image 183
Benoit Garret Avatar answered Sep 19 '22 07:09

Benoit Garret