【问题标题】:skip before action in child controller在子控制器中的操作前跳过
【发布时间】:2017-10-11 15:03:33
【问题描述】:

我有一个应用程序控制器,我正在处理一些身份验证

class ApplicationController < ActionController::Base
  before_action :prep_data
  def prep_data
   # code...
   # authenticate
  end
end

我有一个继承自这个的控制器

class OtherController < ApplicationController
  def custom_action_method
  end
end

对于自定义操作方法custom_action_method,我可以跳过OtherControllerbefore_action 挂钩

【问题讨论】:

    标签: ruby-on-rails ruby


    【解决方案1】:

    我找到了答案,这是语法

    class OtherController < ApplicationController
      skip_before_action :prep_data, only: [:custom_action_method]
    
      def custom_action_method
      end
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-05
      • 2013-05-29
      • 2015-06-21
      • 1970-01-01
      • 1970-01-01
      • 2016-07-29
      • 1970-01-01
      相关资源
      最近更新 更多