1
我用葡萄来建立自己的API的网站,我想添加自动使用日志功能到我的网站,所以我在我的葡萄:: API类使用预先准备,这是我如何做:使用前置包装葡萄API方法
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
但似乎当我请求/信息API我在GrapeExtension代码不叫,为什么呢?
似乎不工作,我发现,即使是** **得到葡萄:: API方法将被调用只有一次在网站初始化时,所以我怀疑是否在这里添加自动使用的日志是正确的地方@Ivan Zarea – TommyLike 2014-09-29 13:41:59