我们在控制器中有以下过滤器:
before_action :authenticate_api_request!, except: [:reply_messages]
before_action :community_uuid
before_action :is_user_blocked?, only: [:create, :like, :dislike, :flag, :reply_message]
before_action :user_confirmed_email?, only: [:create]
before_action :get_message, only: [:like, :dislike, :flag, :remove, :get_message_json, :reply_message, :reply_messages]
before_action :get_reply_message, only: [:reply_message]
before_action :get_group, only: [:create]
before_action :is_blocked_from_group?, only: [:create, :like, :dislike, :reply_message]
它们的执行顺序是:
user_confirmed_email?
get_message
get_reply_message
authenticate_api_request!
community_uuid
is_user_blocked?
get_group
is_blocked_from_group?
这里的问题是在authenticate_api_request!, community_uuid and is_user_blocked?
之后调用user_confirmed_email?
。
它可以在开发和登台环境中正常工作,但不能在qa服务器上使用相同的代码,甚至无法理解为什么即使复制相同的代码也是如此。
答案 0 :(得分:0)
选中Filter Chain Ordering和this other answer。
您必须指定:prepend_before_filter
,以便在链的开头执行过滤器。
请注意,:prepend_before_action
是:prepend_before_filter
,prepend_before_action的别名。
我还没有尝试过,但是您可能会写类似这样的东西:
before_action :user_confirmed_email?, only: [:create]
before_action :get_message, only: [:like, :dislike, :flag, :remove, :get_message_json, :reply_message, :reply_messages]
before_action :get_reply_message, only: [:reply_message]
before_action :get_group, only: [:create]
before_action :is_blocked_from_group?, only: [:create, :like, :dislike, :reply_message]
prepend_before_action :is_user_blocked?, only: [:create, :like, :dislike, :flag, :reply_message]
prepend_before_action :community_uuid
prepend_before_action :authenticate_api_request!, except: [:reply_messages]