简体   繁体   English

如何将Rails devSign_in路径设置为根URL

[英]How to set rails devise sign_in path as a root url

devise_for :admins, path: 'admins' 
devise_scope :admin do
  root to: "devise/sessions#new"
end
http://localhost:3000/

I want to redirect admins/sign_in path when I just enter above url, login page is opening sometimes but after click on login button every time I get this error and not sign in. How to solve this problem? 我只想在url上方输入时就想重定向admins / sign_in路径,登录页面有时会打开,但是每次我遇到此错误而不登录时都单击登录按钮。如何解决此问题?

error: 错误:

Filter chain halted as :require_no_authentication rendered or redirected 由于:require_no_authentication呈现或重定向,过滤链停止

look like you're trying to log in the same user again without a sign out 看起来您正在尝试再次登录同一用户而未注销

devise_for :admins, path: 'admins' 

devise_scope :admin do
  authenticated :admin do
    root 'home#index', as: :authenticated_root
  end

  unauthenticated do
    root 'devise/sessions#new', as: :unauthenticated_root
  end
end

You can achieve the same with this 你可以做到这一点

routes.rb routes.rb

root "home#index"
devise_for :admins, path: 'admins' 

home_controller.rb home_controller.rb

class HomeController < ApplicationController
def index
   if not admin_signed_in?
     redirect_to admin_session_path
   end
end

A logged user can't sign in again... 已登录的用户无法再次登录...

You can try this, in your session_controller.rb add 您可以尝试此操作,在session_controller.rb中添加

class Users::SessionsController < Devise::SessionsController
  prepend_before_filter :require_no_authentication, :only => [ :new, :create, :cancel ]
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM