我试着按照这里的说明: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在“app / controllers /”中
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#在我提交表单时在日志中创建为HTML.我怀疑也许没有调用skip_before_filter:require_no_authentication,但是假设因为EditorsController继承了RegistrationController,之前过滤器才能正常工作.那不是这样吗?
解决方法
您正试图通过skip_before_filter:require_no_authentication来解决该问题,但您的表单可能是POST / to / POSTitors而不是/ admin / editors.因此,您需要添加一个允许您在EditorsController上创建的路由:
as :admin do post 'admin/editors' => 'editors#create' # your other :admin routes here end
然后你想要实现缩小版的create.你可能想要这样的东西:
class EditorsController < Devise::RegistrationsController def create build_resource(sign_up_params) if resource.save redirect_to admin_editors_path else clean_up_passwords resource respond_with resource end end # your other methods here end
您还需要确保admin / editors / new模板将表单指向正确的路径(‘admin / editors’).
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。