How to use 'before_action' in a module

后端 未结 1 741
忘掉有多难
忘掉有多难 2021-02-06 23:14

I would like to use \'before_action\' in a module.

Unfortunately, I couldn\'t get it work.

I was googleing, but everything I found couldn\'t solve the problem.

1条回答
  •  野性不改
    2021-02-07 00:19

    I think this is what you're trying to do:

    class SomeController < ActionController::Base
      include SimpleController
    end 
    
    module SimpleController
      extend ActiveSupport::Concern
    
      included do
        before_action :set_object, only: [:show]
      end
    end
    

    0 讨论(0)
提交回复
热议问题