我有一个devise
设置,其中包含3个不同的用户,这些用户也拥有自己的sessions/registrations controllers
和自己的models
。
我还为after sign-in path
def after_sign_in_path_for(resource)
case resource
when Admin
admin_index_path
when Seller
stored_location_for(resource) || seller_account_path(current_seller)
when Buyer
redirect_back(fallback_location: root_path)
else
permission_denied
end
end
admin and seller after sing-in path
工作正常,但当buyer signs-in
返回此错误时:
AbstractController::DoubleRenderError in Buyers::SessionsController#create
Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like "redirect_to(...) and return".
错误发生在买方super
sessions_contoller.rb
行
def create
super
end
我正在尝试将buyer
重定向到同一页面!
关于如何解决这个问题的任何想法?
答案 0 :(得分:0)
我找到了解决方法:
在我的application_contoller.rb
before_action :store_buyer_location!, if: :storable_location?
private
def storable_location?
request.get? && is_navigational_format? && !devise_controller? && !request.xhr?
end
def store_buyer_location!
# :buyer is the scope we are authenticating
store_location_for(:buyer, request.fullpath)
end
并更改买家的登录后路径:
def after_sign_in_path_for(resource)
case resource
when Admin
admin_index_path
when Seller
stored_location_for(resource) || seller_account_path(current_seller)
when Buyer
stored_location_for(resource) || super
else
permission_denied
end
end
答案 1 :(得分:0)
在create
控制器上注释掉session
方法,因为您不需要覆盖此方法,因为没有任何功能而没有devise
默认功能。
我不会'知道如何定义Admin
Seller
和Buyer
,如果您为那些创建method
,那么您可以重写after_sign_in_path_for
方法,如下所示
def after_sign_in_path_for(resource)
if resource.column_name == 'Admin'
admin_index_path
elsif resource.column_name == 'Seller'
stored_location_for(resource) || seller_account_path(current_seller)
elsif resource.column_name == 'Buyer'
redirect_back(fallback_location: root_path)
else
permission_denied
end
end
希望有所帮助