Skip to content

Instantly share code, notes, and snippets.

@ziyadbasheer
Created December 30, 2014 21:00
Show Gist options
  • Save ziyadbasheer/d9276d9cc8b45791caa0 to your computer and use it in GitHub Desktop.
Save ziyadbasheer/d9276d9cc8b45791caa0 to your computer and use it in GitHub Desktop.
if params[:name] == nil
if params[:date]
if params[:length]
@programs = Program.where("startdate between ? and ?", @chosendate.weeks_ago(2), @chosendate.weeks_since(2)).where("minlength between ? and ?", @chosenlength - 2, @chosenlength + 2)
@happens = 'by date and length'
else
@programs = Program.where("startdate between ? and ?", @chosendate.weeks_ago(2), @chosendate.weeks_since(2))
@happens = 'by date'
end
else
@programs = Program.where("minlength between ? and ?", @chosenlength - 2, @chosenlength + 2)
@happens = 'by length'
end
elsif params[:date] == nil
if params[:name]
if params[:length]
@programs = Program.where("name LIKE ? OR description LIKE ?", params[:name], params[:name]).where("minlength between ? and ?", @chosenlength - 2, @chosenlength + 2)
@happens = 'by name and length'
else
@programs = Program.where("name LIKE ? OR description LIKE ?", params[:name], params[:name])
@happens = 'by name'
end
else
@programs = Program.where("minlength between ? and ?", @chosenlength - 2, @chosenlength + 2)
@happens = 'by length'
end
elsif params[:length] == nil
if params[:name]
if params[:date]
@programs = Program.where("name LIKE ? OR description LIKE ?", params[:name], params[:name]).where("startdate between ? and ?", @chosendate.weeks_ago(2), @chosendate.weeks_since(2))
@happens = 'by name and date'
else
@programs = Program.where("name LIKE ? OR description LIKE ?", params[:name], params[:name])
@happens = 'by name'
end
else
@programs = Program.where("startdate between ? and ?", @chosendate.weeks_ago(2), @chosendate.weeks_since(2))
@happens = 'by date'
end
else
@programs = Program.where("name LIKE ? OR description LIKE ?", params[:name], params[:name]).where("startdate between ? and ?", @chosendate.weeks_ago(2), @chosendate.weeks_since(2)).where("minlength between ? and ?", @chosenlength - 2, @chosenlength + 2)
@happens = 'by all'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment