将设计登录设置为根页面 [英] Setting Devise Login to be root page

查看:11
本文介绍了将设计登录设置为根页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的路线使用以下代码:

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=>"设计/会话"}

No route matches {:action=>"new", :controller=>"devise/sessions"}

如何将根路径设置为 :sign_in 操作?

How do I setup the root path to be to :sign_in action?

推荐答案

从询问错误的人那里跟进 Could not find devise mapping for path "/" 有一个解决方法.

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

这对我来说很好

这篇关于将设计登录设置为根页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆