Skip to content

Instantly share code, notes, and snippets.

@phudgins
Created February 14, 2012 19:50
Show Gist options
  • Save phudgins/1829662 to your computer and use it in GitHub Desktop.
Save phudgins/1829662 to your computer and use it in GitHub Desktop.
Getting count of JobApplications by day for a specific JobPosting
def counts_by_day_for_job_posting(job_posting_id)
results = JobApplication.where(job_posting_id: job_posting_id).
where(created_at: 1.month.ago..Time.now).
group('date(created_at)').count
counts = []
results.each do |result|
h = { date: Date.parse(result.first),
job_posting_id: job_posting_id,
application_count: result.last }
counts << h
end
counts
end
puts counts_by_day_for_job_posting(192).to_json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment