简体   繁体   中英

Rails 3 Impressionist indexing by day

I am using the 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.

@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.

尝试这个:

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

You can get 1 week ago date like this

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.

I tried impressionist with mongoid but the filter function didn't work at all in my enviroment.

i hope it does in your app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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