Created
March 14, 2011 01:38
-
-
Save linusthe3rd/868644 to your computer and use it in GitHub Desktop.
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 index | |
query = '' | |
queryHash = Hash.new | |
if params[:min_age] | |
append_to_query(query, 'min_age >= :min_age') | |
queryHash[:min_age] = params[:min_age] | |
end | |
if params[:max_age] | |
append_to_query(query, 'max_age <= :max_age') | |
queryHash[:max_age] = params[:max_age] | |
end | |
if params[:min_price] | |
append_to_query(query, 'price >= :min_price') | |
queryHash[:min_price] = params[:min_price] | |
end | |
if params[:max_price] | |
append_to_query(query, 'price <= :max_price') | |
queryHash[:max_price] = params[:max_price] | |
end | |
if (query.length > 0) | |
@programs = @camp.programs.where(query, queryHash).order('name') | |
else | |
@programs = @camp.programs | |
end | |
if params[:start_date] | |
@programs = @programs.joins(:sessions).where('sessions.start_date >= ?', params[:start_date].to_date) | |
end | |
if params[:end_date] | |
@programs = @programs.joins(:sessions).where('sessions.end_date <= ?', params[:end_date].to_date) | |
end | |
#problem occurring on these named scopes | |
if params[:open] and params[:closed] | |
error(400, 400, "it's a silly query to search for programs that are both closed AND open") | |
elsif params[:open] | |
@programs = @programs.open | |
elsif params[:closed] | |
@programs = @programs.closed | |
end | |
if @programs | |
respond_to do |format| | |
format.html # index.html.erb | |
format.xml { render :xml => @programs } | |
end | |
else | |
respond_to do |format| | |
format.html { render :action => "index", :status => :not_found } | |
format.xml { render :xml => @programs.errors, :status => :bad_request } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment