Log*_*ley 76 ruby-on-rails devise ruby-on-rails-3
我为我的路线使用以下代码:
devise_for :user,
:as => '',
:path_names => {
:sign_in => "",
:sign_out => "logout",
:sign_up => "register"
}
Run Code Online (Sandbox Code Playgroud)
但是当我退出并且我转到后,/logout我收到以下错误:
没有路由匹配{:action =>"new",:controller =>"devise/sessions"}
如何设置要:sign_in采取行动的根路径?
Pet*_*xey 114
要从询问错误的人Could not find devise mapping for path "/"那里继续,有一个解决方法.
你会发现你的日志中有一条线索可能会说:
[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]
Run Code Online (Sandbox Code Playgroud)
所以我重新尝试了这个方法,而是将它包装起来(如@miccet suggets)在一个范围块中:
devise_scope :user do
root to: "devise/sessions#new"
end
Run Code Online (Sandbox Code Playgroud)
这对我来说很好
VvD*_*PzZ 84
devise_for :users
devise_scope :user do
authenticated :user do
root 'home#index', as: :authenticated_root
end
unauthenticated do
root 'devise/sessions#new', as: :unauthenticated_root
end
end
Run Code Online (Sandbox Code Playgroud)
就像这样,在Rails Rails 4.1.0.rc1上测试.
Log*_*ley 23
root :to => "devise/sessions#new"
Run Code Online (Sandbox Code Playgroud)
我需要设置默认的home root.我觉得昨晚(在发布问题之前)我整夜都试过这个,但它现在正在运作.如果您已注销,Devise会尝试将您重定向到我未定义的根路径.
Gil*_*il' 14
(这是作为建议的编辑发布的,但应该是它自己的答案.我不知道它是否有意义.亲爱的匿名编辑:随意将此答案重新发布为您自己的,并留下评论所以我会删除这个副本.)
root :to => redirect("/users/login")
Run Code Online (Sandbox Code Playgroud)
我得到这个与@VvDPzZ答案一起工作.但我不得不稍微修改它
devise_scope :business_owner do
authenticated do
root to: 'pages#dashboard'
end
unauthenticated do
root to: 'devise/sessions#new', as: 'unauthenticated_root'
end
end
Run Code Online (Sandbox Code Playgroud)
我必须to:在根路径声明中做广告.我也删除了as: :authenticated_root因为我已经在我的应用程序中有一些地方引用root_path链接.通过省略as: :authenticated_root部分,我不必更改任何现有链接.