我使用grape来构建我的api网站,我想在我的网站上添加自动使用的日志功能,所以我在我的Grape::API类中使用了prepend,这就是我是如何做到的:
module GrapeExtension
def get(paths = ['/'], options = {}, &block)
#add log code here
super
end
end并将代码添加到我使用的地方::API,例如
class API < Grape::API
prepend GrapeExtension
#other code
get '/info' do
#function code
end
end但是当我请求/info接口时,我的GrapeExtension代码似乎没有被调用,为什么?
发布于 2014-09-29 15:33:50
尝试将paths=['/']替换为通用路径处理程序,如下所示:
module GrapeExtension
def get(paths = ['/*'], options = {}, &block)
#add log code here
super
end
endhttps://stackoverflow.com/questions/26092092
复制相似问题