Created
January 12, 2012 16:43
-
-
Save sgharms/1601528 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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