Skip to content

Instantly share code, notes, and snippets.

@sgharms
Created January 12, 2012 16:43
Show Gist options
  • Save sgharms/1601528 to your computer and use it in GitHub Desktop.
Save sgharms/1601528 to your computer and use it in GitHub Desktop.
class Employee < ActiveRecord::Base
...
def recent_tasks(options = {})
completed_on = if options[:completed_on].present?
Date.parse options[:completed_on]
else
Date.current
end
completed_on = 2.business_days.after(completed_on.to_time).to_date
last_five_days = tasks.select('DISTINCT(completed_on)').where('completed_on <= ?', completed_on).order('completed_on DESC').limit(5).collect{|task| task.completed_on}
tasks.where(:completed_on => last_five_days).order('completed_on DESC')
end
...
end
class TasksController < ApplicationController
respond_to :html,
:only => :index
respond_to :json
...
def index
@tasks = current_employee.recent_tasks params
response.headers['Cache-Control'] = 'no-store'
...
respond_with @tasks
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment