Skip to content

Instantly share code, notes, and snippets.

@daybreaker
Created May 21, 2013 05:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daybreaker/5617610 to your computer and use it in GitHub Desktop.
Save daybreaker/5617610 to your computer and use it in GitHub Desktop.
# model
class Survey < ActiveRecord::Base
CONDITIONS = ["surveys.hotel_id IS NOT NULL"]
end
# controller
conditions = Survey::CONDITIONS
unless params[:time_period].blank?
conditions << "surveys.created_at > '#{params[:time_period].to_i.months.ago}'"
end
logger.info conditions.inspect
# locally, conditions.inspect will always have only one condition fpr the created_at, eg:
# ["surveys.hotel_id IS NOT NULL", "surveys.created_at > '2011-05-21 01:08:19 -0400'"]
# On Amazon EC2, they keep getting added on, eg:
# ["surveys.hotel_id IS NOT NULL", "surveys.created_at > '2011-05-21 01:08:19 -0400'", "surveys.created_at > '2012-05-21 01:08:37 -0400'"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment