设置设计登录为root页面 [英] Setting Devise Login to be root page
问题描述
我正在为我的路线使用以下代码:
I am using the following code for my routes:
devise_for :user,
:as => '',
:path_names => {
:sign_in => "",
:sign_out => "logout",
:sign_up => "register"
}
但是当我登出后,我转到 / logout
我收到以下错误:
But when I'm logged out and I goto /logout
I get the following error:
没有路由匹配{:action =>new ,
:controller =>devise / sessions}
No route matches {:action=>"new", :controller=>"devise/sessions"}
如何设置根路径为:sign_in
action?
How do I setup the root path to be to :sign_in
action?
推荐答案
关于错误找不到路径/的设计映射
有一个解决方法。
To follow on from the people who are asking about the error Could not find devise mapping for path "/"
there is a workaround.
你会发现你的日志中有一个线索,可能会说:
You'll find that there is a clue in your logs which will probably say:
[Devise] Could not find devise mapping for path "/".
This may happen for two reasons:
1) You forgot to wrap your route inside the scope block. For example:
devise_scope :user do
match "/some/route" => "some_devise_controller"
end
2) You are testing a Devise controller bypassing the router.
If so, you can explicitly tell Devise which mapping to use:
@request.env["devise.mapping"] = Devise.mappings[:user]
所以我重试了这个方法,而是将它(作为@miccet suggets)包含在一个范围块中:
So I retried the approach but instead wrapping it (as @miccet suggets) inside a scope block:
devise_scope :user do
root to: "devise/sessions#new"
end
这对我来说很好。
这篇关于设置设计登录为root页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!