Created
February 12, 2012 04:03
-
-
Save azuby/1806152 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
heroku production: | |
Shift Load (91.1ms) SELECT DISTINCT shifts.* FROM "shifts" INNER JOIN clocks clocks_between ON clocks_between.shift_id = shifts.id AND clocks_between.datetime BETWEEN '2012-02-03 00:00:00.000000' AND '2012-02-12 23:59:59.999999' | |
local development: | |
Shift Load (1.0ms) SELECT DISTINCT shifts.* FROM "shifts" INNER JOIN clocks clocks_between ON clocks_between.shift_id = shifts.id AND clocks_between.datetime BETWEEN '2012-02-03 08:00:00.000000' AND '2012-02-13 07:59:59.999999' |
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 ShiftsController < ApplicationController | |
load_and_authorize_resource | |
skip_load_resource :only => :index | |
# GET /shifts | |
def index | |
begin | |
start_date = Time.strptime( params[:from].to_s, '%m-%d-%Y') | |
rescue ArgumentError | |
start_date = 1.week.ago.beginning_of_day | |
params[:from] = start_date.strftime("%m-%d-%Y") | |
end | |
begin | |
end_date = Time.strptime( params[:to].to_s, '%m-%d-%Y').end_of_day | |
rescue ArgumentError | |
end_date = Time.now.end_of_day | |
params[:to] = end_date.strftime("%m-%d-%Y") | |
end | |
@shifts = Shift.accessible_by(current_ability).between(start_date, end_date) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
start_date = Date.parse(params[:from]) rescue 1.week.ago
end_date = Date.parse(params[:to]) rescue Date.today
@Shifts = Shift.accessible_by(current_ability).between(start_date.beginning_of_day, end_date.end_of_day)