In rails, there are a lot of helpers to direct our actions, like collections_path
new_member_path
edit_member_path
and so on.
在rails中,有许多帮助器来指导我们的操作,例如collections_path new_member_path edit_member_path等等。
But where is the root? Is there a helper always points to my homepage?
但根在哪里?有帮助者总是指向我的主页吗?
1 个解决方案
#1
44
These helpers exist, but you have to set your root url before, in config/routes.rb
:
这些助手存在,但您必须在config / routes.rb之前设置您的根URL:
root :to => "controller#action"
You can use root_url
and root_path
afterwards.
之后您可以使用root_url和root_path。
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).
请注意,使用_path帮助程序进行重定向时会有一个问题,在重定向时应使用_url(请参阅@ LanguagesNamedAfterCoffee的注释以获取详细信息)。
#1
44
These helpers exist, but you have to set your root url before, in config/routes.rb
:
这些助手存在,但您必须在config / routes.rb之前设置您的根URL:
root :to => "controller#action"
You can use root_url
and root_path
afterwards.
之后您可以使用root_url和root_path。
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).
请注意,使用_path帮助程序进行重定向时会有一个问题,在重定向时应使用_url(请参阅@ LanguagesNamedAfterCoffee的注释以获取详细信息)。