我试图让它只有管理员可以添加用途与设计。我已经得到它主要工作,但现在当我作为管理员登录,并提交注册形式它踢我回来的错误: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