[英]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/
我只想在url上方輸入時就想重定向admins / sign_in路徑,登錄頁面有時會打開,但是每次我遇到此錯誤而不登錄時都單擊登錄按鈕。如何解決此問題?
錯誤:
由於:require_no_authentication呈現或重定向,過濾鏈停止
看起來您正在嘗試再次登錄同一用戶而未注銷
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
你可以做到這一點
routes.rb
root "home#index"
devise_for :admins, path: 'admins'
home_controller.rb
class HomeController < ApplicationController
def index
if not admin_signed_in?
redirect_to admin_session_path
end
end
已登錄的用戶無法再次登錄...
您可以嘗試此操作,在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.