Created
November 28, 2011 05:19
-
-
Save rdeguzman/1399202 to your computer and use it in GitHub Desktop.
How to merge conditions hash with parameters
This file contains 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
def gps_activity | |
@sidebar_units = Unit.where(:fleet_id => @chosen_fleets_array).not_hidden.order("NAME") | |
unless params[:unit_ids].blank? | |
@chosen_units_array = params[:unit_ids] | |
else | |
@chosen_units_array = @sidebar_units.collect{ |u| [u.id]} | |
end | |
conditions = {:fleet_id => @chosen_fleets_array} | |
unless params[:datetime_start].blank? and params[:datetime_end].blank? then | |
dt_start = DateTime.strptime(params[:datetime_start], "%m/%d/%Y %H:%M").to_i | |
dt_end = DateTime.strptime(params[:datetime_end], "%m/%d/%Y %H:%M").to_i | |
#conditions.merge!( :gps_timestamp => " >= #{dt_start}" ) | |
#conditions.merge!( :gps_timestamp => " <= #{dt_end}" ) | |
end | |
#@histories = GpsHistory.where(conditions).order("gps_timestamp DESC") | |
@histories = GpsHistory.where(conditions). | |
where("gps_timestamp >= ?", dt_start). | |
where("gps_timestamp <= ?", dt_end). | |
order("gps_timestamp DESC") | |
#SELECT "gps_histories".* FROM "gps_histories" | |
#WHERE "gps_histories"."fleet_id" IN (4000) | |
#AND (gps_timestamp >= 1321959600) | |
#AND (gps_timestamp <= 1321963200) | |
#ORDER BY gps_timestamp DESC | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment