设计:不能关闭require_no_authentication? [英] Devise: Can't turn off require_no_authentication?

查看:228
本文介绍了设计:不能关闭require_no_authentication?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试限制访问注册,这似乎是不可能的。我试过

When i try to restrict access to signup, it seems impossible. I tried

class RegistrationsController < Devise::RegistrationsController
  skip_before_filter :require_no_authentication
end

在app / registrations_controller.rb并改变路线

in app/registrations_controller.rb and changed routes to

devise_for :accounts, :controllers => { :registrations => "registrations" }

这是行不通的。任何建议,为什么,什么我可以做/我应该在哪里看是AP preciated。

This does not work. Any suggestions why and what i could do/where i should look would be appreciated.

编辑:

不工作的手段:当我尝试访问/帐号/ sign_up而被注销,它的实际工作,但我应该被重定向到sign_in

Does not work means: when i try to access /accounts/sign_up while being signed out, it actually works, but i should be redirected to sign_in.

解决方法:

class RegistrationsController < Devise::RegistrationsController
  skip_before_filter :require_no_authentication

  private

  def authenticate_account!(opts={})
    opts[:scope] = :account
    warden.authenticate!(opts) # if !devise_controller? || opts.delete(:force)
  end
end

这将删除硬盘codeD检查,对于每一个设计控制器跳过验证。在code来自的lib /设计/控制器/ helpers.rb

This removes the hardcoded check that skips authentication for EVERY Devise-controller. The code comes from lib/devise/controllers/helpers.rb.

推荐答案

所以,你想<一个href=\"https://github.com/plataformatec/devise/wiki/How-To%3a-Change-the-redirect-path-after-destroying-a-session-i.e.-signing-out\"相对=nofollow>注销路径后的变化。

如果您还没有设置你的根在随后制定的迹象

If you haven't set your root to devise sign in then

class ApplicationController < ActionController::Base
  private

  # Overwriting the sign_out redirect path method
  def after_sign_out_path_for(resource_or_scope)
    new_user_session_path
  end
end

这篇关于设计:不能关闭require_no_authentication?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆