我試圖讓它只有管理員可以添加用途與設計。我已經得到它主要工作,但現在當我作爲管理員登錄,並提交註冊形式它踢我回來的錯誤:You are already signed in.
允許管理員添加用戶與設計
我試圖按照這裏的說明:http://wiki.summercode.com/rails_authentication_with_devise_and_cancan但它似乎沒有提到這種情況。
我是否需要在editors_controller
中進一步覆蓋以允許這樣做?
這裏是我的路線( 「編輯」 我的用戶模型的名稱):
devise_for :admins, :skip => [:registrations]
as :admin do
get 'admin/editors' => 'editors#index', as: :admin_editors
get 'admin/editors/new' => 'editors#new', as: :new_editor
delete 'admin/editors/:id' => 'editors#destroy', as: :destroy_editor
end
devise_for :editors, :skip => [:registrations], :controllers => { :registrations => "editors" }
在
和我editors_controller
「應用程序/控制器/」
class EditorsController < Devise::RegistrationsController
before_filter :check_permissions, :only => [:new, :create, :cancel]
skip_before_filter :require_no_authentication
def dashboard
render "editors/dashboard.html.haml"
end
def index
@editors = Editor.all
respond_to do |format|
format.html
end
end
private
def check_permissions
authorize! :create, resource
end
end
編輯 我我在提交表單時在日誌中注意到這個Processing by Devise::RegistrationsController#create as HTML
。我曾懷疑可能是skip_before_filter :require_no_authentication
沒有被調用,但假設因爲EditorsController
從RegistrationController
繼承過濾器將正常工作之前。情況並非如此嗎?
hello Jeremey我已經嘗試過你的創建動作,但它仍然繞過表單,並用「你已經登錄」的信息舔我。有任何想法嗎? – BKSpurgeon