我正在为我的应用程序使用mixpanel gem。它充当中间件并动态地将代码插入头部以进行任何操作。我希望能够针对特定操作将其关闭(例如,我们有一个发送电子邮件的操作,我们宁愿没有代码)。关于如何做到这一点的任何想法?
非常感谢。
我正在为我的应用程序使用mixpanel gem。它充当中间件并动态地将代码插入头部以进行任何操作。我希望能够针对特定操作将其关闭(例如,我们有一个发送电子邮件的操作,我们宁愿没有代码)。关于如何做到这一点的任何想法?
非常感谢。
似乎 mixpanel 已经更新了他们的 gem
防止中间件插入代码
注意:仅在设置机架中间件时适用。
有时您可能需要发送不希望中间件更改的 HTML 请求。在您的 AJAX 请求中包含标题“SKIP_MIXPANEL_MIDDLEWARE”以防止插入混合面板代码。$.ajax("/path/to/api/endpoint", { headers: {"Skip-Mixpanel-Middleware": true}, // valid http headers don't allow underscores and get filtered by some webservers success: function(data) { // Process data here } }); //Alternatively, you can add this line of code to your controller to temporarily disable the middleware: Mixpanel::Middleware.skip_this_request
取自: https ://github.com/zevarito/mixpanel#prevent-middleware-from-inserting-code
From the Mixpanel docs:
In your application_controller class add a method to instance mixpanel.
before_filter :initialize_mixpanel def initialize_mixpanel @mixpanel = Mixpanel::Tracker.new("YOUR_MIXPANEL_API_TOKEN", request.env, true) end
Since it's initialized by a before_filter
you can use skip_before_filter
in your other controllers to, well, skip it for certain actions, or for all except a certain action, e.g.:
class SomeController < ActionController::Base
skip_before_filter :initialize_mixpanel, :only => [ :create, :new ]
# or
skip_before_filter :initialize_mixpanel, :except => [ :update ]
end
我们想不出办法做到这一点,最终在事后将其剥离(使用 gsub)。如果其他人有更好的解决方案,我肯定会将你的解决方案标记为正确,我只想结束这个问题。谢谢