0
我使用Google Analytics API的Garb Ruby包装为我的应用程序构建了一个pageview计数器。这样做意味着在“LIB”文件夹中创建一个新的模块,我在其中创建这样一个类:在Rails中,有没有办法在类(不是控制器)中调用request.request_uri?
#lib/Analyze.rb
...
class Report
extend Garb::Resource
metrics :pageviews
dimensions :page_path
filters :page_path.eql => '/' #the path of the page I instantiate this class on
end
#followed by a method for instantiating this class
我需要过滤器:page_path.eql =>是在我称之为页面的路径方法。我尝试了像request.request_uri或url_for(:action =>'show':controllers =>'users':id => params [:id])但不知道如何在这个类中指定页面路径定义。
将请求数据传回类是什么样的?我知道我不能将一个变量传递给类定义。对不起,还是一个相当新的程序员。 – kateray 2010-10-13 15:23:12
我想你想为每个页面构建一次性报告 - 我已经更新了我的回答 – Codebeef 2010-10-13 16:01:10
好的,这对我有用,但也会让它变慢。如果你想出任何其他的方式,爱知道。谢谢。 – kateray 2010-10-13 16:24:15