Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 如何将ActiveSupport::Concern应用于控制器中的特定操作?_Ruby_Grape_Activesupport Concern - Fatal编程技术网

Ruby 如何将ActiveSupport::Concern应用于控制器中的特定操作?

Ruby 如何将ActiveSupport::Concern应用于控制器中的特定操作?,ruby,grape,activesupport-concern,Ruby,Grape,Activesupport Concern,我正在使用Grape构建一个API 我创建了一个名为Authentication的ActiveSupport::Concern并应用了一些before过滤器,因此我的关注点看起来像: module Authentication extend ActiveSupport::Concern included do before do error!('401 Unauthorized', 401) unless authenticated? end ...

我正在使用Grape构建一个API

我创建了一个名为
Authentication
ActiveSupport::Concern
并应用了一些before过滤器,因此我的关注点看起来像:

module Authentication
  extend ActiveSupport::Concern

  included do
    before do
      error!('401 Unauthorized', 401) unless authenticated?
    end
    ....
  end
end
现在,让我们假设在我的UserController中,我只想将此关注点应用于特定的操作。我该怎么做

  class SocialMessagesController < Grape::API
    include Authentication

    get '/action_one' do
    end

    get '/action_two' do
    end

  end
class SocialMessageController
是否有任何简单的方法可以指定特定方法的关注点,就像rails中带有
only
选项的
before\u filter