Ruby Grape 过滤器如何过滤掉 API 方法 (语法不清楚)

return · December 21, 2016 · Last by return replied at December 21, 2016 · 1842 hits
module API
  # Projects API
  class Repositories < Grape::API
    before { authenticate! }
    before { authorize! :download_code, user_project }
    resource :projects do
      ...
      ....

      #   GET /projects/:id/repository/test
      get ':id/repository/test' do
          content...
      end
    end
  end
end

上面的代码中,我想在第一个 before { authenticate! } 中 except 掉 tree,即调 test api 的时候不走 authenticate!,请问语法上该怎么写? 感谢!

@huacnlee 求教,感谢~

@Rei @lgn21st @hooopo @lyfi2003 大家谁有时间帮我看看这个问题,谢谢!

自己查文档啊

#3 楼 @chenge api 文档中貌似没有这类用法...

肯定有,似乎是,before_filter

6 Floor has deleted

#5 楼 @chenge 我知道 :except => [:action] 但是这里的 aciton 是以 get 形式 get ':id/repository/test' 这种情况不太清楚怎么写,能不能解释下,谢谢!

你这个是 grape 吧。应该是方法名字吧。

#8 楼 @chenge 是的,是 grape, 有办法实现吗?before { authenticate! :except => [:test]} and before { authenticate! :test} 语法上都有问题😅

#9 楼 @return 那你标题有问题啊,写的 rails。grape 我不知道哦。

#10 楼 @chenge 恩恩,是的,我没说清楚,grape 的怎么写呢?求指教

#12 楼 @placeintime 非常感谢,我明白了👍 👍 👍 👍 👍 👍 👍

You need to Sign in before reply, if you don't have an account, please Sign up first.