简体   繁体   English

Rails 3印象派索引

[英]Rails 3 Impressionist indexing by day

I am using the Ruby gem Impressionist. 我正在使用Ruby gem Impressionist。 It gives you the ability to look at a count of page hits from a specific date to today date. 它使您能够查看从特定日期到今天的页面点击计数。 I'm trying to get the hits from the past 7 days but spit out the number for each day. 我试图获取过去7天的点击率,但每天吐出的数字却很高。

@widget.impressionist_count(:start_date=>"2011-01-01")  #specify start date only, end date = now

How would I do that? 我该怎么做? I want 7 days ago but for each day to give me the exact count for that day. 我想要7天前,但每天要给我当天的确切计数。

尝试这个:

@widget.impressionist_count(:start_date => 1.week.ago)

You can get 1 week ago date like this 您可以这样获得1个星期前的日期

t = Time.now
lastweek = t - 1.week

and then you can do like this 然后你可以这样做

@widget.impressionist_count(:start_date=>lastweek.strftime('%Y-%m-%d'))

I guess you shold do this in controller, or you can pass just the last week date to the view. 我猜您应该在控制器中执行此操作,也可以仅将上周日期传递给视图。 This code works in Rails app cause it uses active_support. 此代码在Rails应用程序中有效,因为它使用active_support。

I tried impressionist with mongoid but the filter function didn't work at all in my enviroment. 我尝试过使用印象模样与mongoid进行交互,但是在我的环境中,过滤器功能根本不起作用。

i hope it does in your app. 我希望它能在您的应用程序中使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM