【问题标题】:before_filter running out of order, working fine in dev and staging env. but not working on qa envbefore_filter 出现故障,在 dev 和 staging 环境中运行良好。但不适用于 qa 环境
【发布时间】:2018-11-22 14:44:04
【问题描述】:

我们在控制器中有以下过滤器:

  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? 之后被调用。

它在 dev 和 staging 环境中正常工作,但在 qa 服务器上不能工作相同的代码,即使复制相同的代码也不明白为什么会发生这种情况。

【问题讨论】:

标签: ruby-on-rails ruby ruby-on-rails-3


【解决方案1】:

检查Filter Chain Orderingthis other answer

您必须指定:prepend_before_filter,以便您的过滤器在链的开头执行。

注意:prepend_before_action:prepend_before_filterprepend_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]

【讨论】:

  • 我们不需要这个,因为“它在 dev 和 staging 环境中工作正常,但在 qa 服务器上不能工作相同的代码,即使复制相同的代码也不明白为什么会发生这种情况。”
猜你喜欢
  • 2010-11-24
  • 1970-01-01
  • 2013-11-27
  • 1970-01-01
  • 2020-11-25
  • 2019-04-06
  • 1970-01-01
  • 1970-01-01
  • 2012-01-23
相关资源
最近更新 更多