我正在为我的应用程序创建一个 JSON API。我想将 rocket_pants 用于 JSON API 和 doorkeeper 以提供 OAuth2 支持。
我的问题是,一旦我将 Controller 更改为扩展火箭裤 Controller ,门卫方法似乎就不再可用。
所以,一旦我将 Controller 的声明更改为 class Api::V1::ApiController < RocketPants::Base
,我收到此错误:
in `<class:ApiController>': undefined method `doorkeeper_for' for Api::V1::ApiController:Class (NoMethodError)
这可能是有道理的,因为火箭裤无法知道门卫,但我想知道我应该怎么做才能让它识别门卫。
最佳答案
如果您使用 doorkeeper 0.4.1 或更高版本,您可以将 doorkeeper 过滤器添加到您的 Controller :
class MetalController < ActionController::Metal
include AbstractController::Callbacks # you might want to skip this for rocket_pants based controller
include ActionController::Head
include Doorkeeper::Helpers::Filter
doorkeeper_for :all
def index
self.response_body = { :ok => true }.to_json
end
end
因为 rocket_pants 已经包含 AbstractController::Callbacks
你可以跳过它,所以你的 Controller 看起来像:
class MetalController < RocketPants::Base
include ActionController::Head
include Doorkeeper::Helpers::Filter
version 1
doorkeeper_for :all
end
wiki 上的这个页面也可能有用:https://github.com/applicake/doorkeeper/wiki/ActionController::Metal-with-doorkeeper
关于ruby-on-rails-3 - 如何在同一个 Rails 应用程序中同时使用火箭裤和门卫?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11383111/