问题
When i try to restrict access to signup, it seems impossible. I tried
class RegistrationsController < Devise::RegistrationsController
skip_before_filter :require_no_authentication
end
in app/registrations_controller.rb and changed routes to
devise_for :accounts, :controllers => { :registrations => "registrations" }
This does not work. Any suggestions why and what i could do/where i should look would be appreciated.
EDIT:
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.
WORKAROUND:
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
This removes the hardcoded check that skips authentication for EVERY Devise-controller. The code comes from lib/devise/controllers/helpers.rb
.
回答1:
So you want to change after sign-out path.
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
来源:https://stackoverflow.com/questions/20766081/devise-cant-turn-off-require-no-authentication