在我的应用程序控制器有之前的代码,这应该是将每种类型的用户重定向到适当的页面后登录。当每种类型的用户注册时,它们应该被重定向到根页面,这与注销是一样的。当我点击“登录”或“注册”按钮时,我将重定向到customer_dashboard,而不是登录或注册页面。当我点击退出时,我得到了这个错误Cannot redirect to nil!,在添加这些重定向方法之前,当我点击每个按钮时,它们会链接到正确的页面登录和注册。这个代码有什么问题?是否有一些逻辑,代码是丢失的,以使这个网站工作?
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_action :authenticate!
def after_sign_in_path_for(resource)
case resource
when Customer then customer_dashboard_path
when Vendor then stored_location_for(:vendors) || vendor_dashboard_path
end
end
def after_sign_out_path_for(resource)
case resource
when Customer then root_path
when Vendor then stored_location_for(:vendors) || root_path
end
end
def after_inactive_sign_up_path_for(resource)
case resource
when Customer then root_path
when Vendor then stored_location_for(:vendors) || root_path
end
end
def authenticate!
if @current_user == current_customer
:authenticate_customer!
elsif @current_user == current_vendor
:authenticate_vendor!
end
end
end所以我添加了skip_before_filter :身份验证!对于所有4个控制器和路由问题仍然存在。
class Vendors::RegistrationsController < Devise::RegistrationsController
# before_action :configure_sign_up_params, only: [:create]
# before_action :configure_account_update_params, only: [:update]
skip_before_filter :authenticate!
# GET /resource/sign_up
# def new
# super
# end
# POST /resource
# def create
# super
# end
# GET /resource/edit
# def edit
# super
# end
# PUT /resource
# def update
# super
# end
# DELETE /resource
# def destroy
# super
# end
# GET /resource/cancel
# Forces the session data which is usually expired after sign
# in to be expired now. This is useful if the user wants to
# cancel oauth signing in/up in the middle of the process,
# removing all OAuth session data.
# def cancel
# super
# end
# protected
# If you have extra params to permit, append them to the sanitizer.
# def configure_sign_up_params
# devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute])
# end
# If you have extra params to permit, append them to the sanitizer.
# def configure_account_update_params
# devise_parameter_sanitizer.permit(:account_update, keys: [:attribute])
# end
# The path used after sign up.
# def after_sign_up_path_for(resource)
# super(resource)
# end
# The path used after sign up for inactive accounts.
# def after_inactive_sign_up_path_for(resource)
# super(resource)
# end
end发布于 2016-05-10 06:22:48
这是因为在每次操作和路由不正确之前都会调用before_action :authenticate!。
我不认为你的目标是什么,但你必须跳过这之前,过滤之前,一些行动,如你的登录或注册。
https://stackoverflow.com/questions/37130583
复制相似问题