![](/img/trans.png)
[英]With Devise, how have two authenticated_root (for two different user models)
[英]rails devise - how to have 2 devise authentications for two different user models?
我們有admin_users和普通用戶,他們都有單獨的表,模型和設計登錄名。
僅針對一個用戶表使用devise並使用cancan作為角色可能更有意義,但是應用程序已經使用兩個單獨的用戶表創建,因此此時不能更改它們。
管理員用戶的功能(包括登錄名)工作正常。 最初,標准用戶訪問僅通過基於鏈接和令牌的身份驗證進行,但這需要進行更改。
在路線上,我們有
devise_for :admin_users, ActiveAdmin::Devise.config
devise_for :users
resources :users, :only => [:update, :edit]
因此,我添加了由Devise文檔說明的用戶資源的根路徑,作為成功登錄的位置:
devise_for :admin_users, ActiveAdmin::Devise.config
devise_for :users
resources :users, :only => [:update, :edit] do
root to: "practitioner_activities#welcome"
end
然后我也嘗試刪除only =>
eg
devise_for :admin_users, ActiveAdmin::Devise.config
devise_for :users
resources :users do
root to: "practitioner_activities#welcome"
end
對於(常規)用戶模型,我進行了更改:
devise :token_authenticatable,
還具有:
devise :token_authenticatable, # token login still permitted.
:database_authenticatable, :recoverable, :rememberable,
:trackable, :validatable
# Not sure if these will make a difference but they are like this in other apps.
但是不會將用戶重定向到登錄屏幕,而無需重定向到開業者_活動#welcome。
我注意到控制台中為登錄POST記錄的第一行使用的是AdminUser模型,而不是User模型。 任何想法如何解決?
Started POST "/" for 127.0.0.1 at 2012-08-23 13:54:50 -0400
Processing by HelpController#show as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"28iGxAB+URoIKoBQtPizGAosJoZ/V7Vko1w/bYMvesE=", "new_user_session_path"=>{"email"=>"Borger.Cathy@meridianschools.o
rg", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Sign In"}
AdminUser Load (0.4ms) SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = 1 LIMIT 1
登錄表單本身是:
= semantic_form_for(:new_user_session_path,
:html => {:id => "session_new"}) do|f|
= f.inputs do
= f.input :email, :label => "Username"
= f.input :password
= f.input :remember_me, :as => :boolean, :if => false
= f.commit_button "Sign In"
最終,主要的事情是再次只是設計生成器,然后編輯設計視圖。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.