我有这个传统的Spree应用程序,带有2个带有继承回调的装饰控制器:
Spree::Api::BaseController.class_eval do
before_action :load_api_key_user, only: [:index, :show, :jstree]
before_action :override_params, only: [:create, :new]
before_action do
api_key_user = Spree.user_class.by_store(
current_store
).find_by(spree_api_key: api_key.to_s)
if api_key_user && (api_key_user.admin? || api_key_user.manager?)
load_api_key_user
end
end
before_action :load_user
before_action :authenticate_user
before_action :load_user_roles
...
和
Spree::Api::V1::OrdersController.class_eval do
# Allow non authenticated user to perform some actions..
before_action :load_api_key_user, only: [:create, :apply_coupon_code]
before_action :load_user
# only owners of the order are allowed to handle order.
before_action :authorize_for_order, except: [:create, :index, :apply_coupon_code]
before_action :authenticate_user
before_action :load_user_roles
过滤器订单链与具有相同ruby版本(ruby 2.2.1p85)的不同机器以及产生意外行为的相同gem版本不同。我用这个命令检查订单:
Spree::Api::V1::OrdersController._process_action_callbacks.map{|c| "#{c.kind}:#{c.filter}"}
结果与配置相同。
本地计算机:["before:set_user_language", "before:set_version", "before:set_guest_token", "before:set_content_type", "before:set_xhr_redirected_to", "before:set_request_method_cookie", "after:abort_xdomain_redirect", "before:override_params", "before:70133939841780", "before:search_ransack_by_store", "before:search_ransack_by_region", "before:find_order", "before:load_api_key_user", "before:load_user", "before:authorize_for_order", "before:authenticate_user", "before:load_user_roles", "before:remove_email_from_params_if_nil", "before:70133903534220", "before:70133903532720", "before:70133931867720", "before:70133931866900"]
远程机器:["before:set_user_language", "before:set_version", "before:set_guest_token", "before:set_content_type", "before:set_xhr_redirected_to", "before:set_request_method_cookie", "after:abort_xdomain_redirect", "before:find_order", "before:authorize_for_order", "before:remove_email_from_params_if_nil", "before:46966032393140", "before:46966032349400", "before:46966032346700", "before:46966032344600", "before:load_api_key_user", "before:override_params", "before:46966007219340", "before:load_user", "before:authenticate_user", "before:load_user_roles", "before:search_ransack_by_store", "before:search_ransack_by_region"]
所以我有相同的ruby版本和相同的宝石套装。还有什么可以解释这种变化?
答案 0 :(得分:4)
ActionController回调过滤器链不一致。
我在开发MFC项目时遇到过这种情况。
那时,当我作为调试模式运行时,没有错误,当以实模式运行时,出现了RUNTIME错误,我修复了这个错误。
RUNTIME错误是因为函数命令。
事件功能OnCreate和OnResizeWindow引起了我的注意。
debug mode: OnCreate() is called before OnResizeWindow()
real mode: OnCreate() is called after OnResizeWindow()
我认为原因是打断了系统。
然后关于你的项目: 在远程计算机上,将出现比本地计算机更多的中断。
要修复错误,您必须在自己的代码上构建功能订购系统。
答案 1 :(得分:-2)
[“before:set_user_language”,“before:set_version”,“before:set_guest_token”,“before:set_content_type”,“before:set_xhr_redirected_to”,“before:set_request_method_cookie”,“after:abort_xdomain_redirect “,”之前:find_order“,”之前:authorize_for_order“,”之前:remove_email_from_params_if_nil“,”之前:46966032393140“,”之前:46966032349400“,”之前:46966032346700“,”之前:46966032344600“,”之前:load_api_key_user“, “before:override_params”,“before:46966007219340”,“before:load_user”,“before:authenticate_user”,“before:load_user_roles”,“before:search_ransack_by_store”,“before:search_ransack_by_region”]