Jay
Jay

Reputation: 938

Ruby on rails, how to return the amount of days objects were created for that time period

So say I have a channel, and it has many entries. Daily that channel can have entries for many users. I want to be able to report how many entries there were during the week, but I only want to show how many days a entry was created. So I don’t want to show how many entries were created that week, just how many days an entry happened.

example:

channel.entries.for_week(current) returns all of the entries that have been made this week.

I Just want to return the amount of days entries were made for that channel. Anybody have a good solution for this?

Upvotes: 4

Views: 87

Answers (1)

Hass
Hass

Reputation: 1636

I think you can use something like this.

channel.entries.for_week(current).pluck(:created_at).map(&:to_date).uniq.count

Upvotes: 3

Related Questions