【问题标题】:rails dispatch event?轨道调度事件?
【发布时间】:2017-03-29 17:29:50
【问题描述】:

首先,我对gemsengines 完全陌生(嗯。ruby); 我正在编写一个方便的engine,它将根据用户(开发人员)定义的rules 过滤请求,目前我的方法如下:

class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception

  before_action { Acu::Monitor.new request }
end

它的工作原理就像一个魅力,但我希望引擎是即插即用的,用户只需最低配置,有没有我能做到这一点?
我可以在调度和控制器之间的任何地方验证请求吗? Rails 中有类似pre-dispatch-event 的东西吗?

如果有人在这方面帮助我,我将不胜感激,我厌倦了谷歌这个,有点用完了查询来写! :D


更新:

必须处理请求,即目标控制器/动作需要由 rails 确定,然后我正在处理请求。

【问题讨论】:

    标签: ruby-on-rails ruby rubygems ruby-on-rails-5 rails-engines


    【解决方案1】:

    我找到了答案,就是我要找的instrumentation

    ActiveSupport::Notifications.subscribe "start_processing.action_controller" do |**args|
      # your own custom stuff
    end
    

    这样# your own custom stuff 将在before_action 之前开始触发!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-26
      • 2014-01-10
      • 1970-01-01
      相关资源
      最近更新 更多