Permalink
Browse files

a little less duplication for queries.

  • Loading branch information...
1 parent 708f3c5 commit 96f1874ad7cd0d8fed6a1d0a9725b973d6c64608 Dave Kroondyk committed Mar 21, 2013
Showing with 20 additions and 16 deletions.
  1. +9 −7 app/controllers/southie_controller.rb
  2. +11 −9 app/controllers/wicked_controller.rb
@@ -1,12 +1,14 @@
class SouthieController < ApplicationController
def index
- @athletes = Athlete.where(:affiliate => 'southie').order("total asc")
- @individual_men = Athlete.where(:affiliate => 'southie').where('age < 40').where('gender == "Male"').order('total asc')
- @masters_40_44_men = Athlete.where(:affiliate => 'southie').where('age > 39 and age < 45').where('gender == "Male"').order('total asc')
- @masters_50_54_men = Athlete.where(:affiliate => 'southie').where('age > 49 and age < 55').where('gender == "Male"').order('total asc')
- @masters_55_59_men = Athlete.where(:affiliate => 'southie').where('age > 54 and age < 60').where('gender == "Male"').order('total asc')
- @masters_60_men = Athlete.where(:affiliate => 'southie').where('age > 60').where('gender == "Male"').order('total asc')
- @individual_women = Athlete.where(:affiliate => 'southie').where('age < 40').where('gender == "Female"').order('total asc')
+ athletes = Athlete.where(:affiliate => 'southie').order('total asc')
+ male_athletes = athletes.where("gender == 'Male'")
+ female_athletes = athletes.where("gender == 'Female'")
+ @individual_men = male_athletes.where('age < 40')
+ @masters_40_44_men = male_athletes.where('age > 39 and age < 45')
+ @masters_50_54_men = male_athletes.where('age > 49 and age < 55')
+ @masters_55_59_men = male_athletes.where('age > 54 and age < 60')
+ @masters_60_men = male_athletes.where('age > 60')
+ @individual_women = female_athletes.where('age < 40')
end
end
@@ -1,14 +1,16 @@
class WickedController < ApplicationController
def index
- @athletes = Athlete.where(:affiliate => 'wicked').order("total asc")
- @individual_men = Athlete.where(:affiliate => 'wicked').where('age < 40').where('gender == "Male"').order('total asc')
- @masters_40_44_men = Athlete.where(:affiliate => 'wicked').where('age > 39 and age < 45').where('gender == "Male"').order('total asc')
- @masters_45_49_men = Athlete.where(:affiliate => 'wicked').where('age > 44 and age < 50').where('gender == "Male"').order('total asc')
- @masters_50_54_men = Athlete.where(:affiliate => 'wicked').where('age > 49 and age < 55').where('gender == "Male"').order('total asc')
- @individual_women = Athlete.where(:affiliate => 'wicked').where('age < 40').where('gender == "Female"').order('total asc')
- @masters_40_44_women = Athlete.where(:affiliate => 'wicked').where('age > 39 and age < 45').where('gender == "Female"').order('total asc')
- @masters_45_49_women = Athlete.where(:affiliate => 'wicked').where('age > 44 and age < 50').where('gender == "Female"').order('total asc')
- @masters_55_59_women = Athlete.where(:affiliate => 'wicked').where('age > 54 and age < 60').where('gender == "Female"').order('total asc')
+ athletes = Athlete.where(:affiliate => 'wicked').order('total asc')
+ male_athletes = athletes.where("gender == 'Male'")
+ female_athletes = athletes.where("gender == 'Female'")
+ @individual_men = male_athletes.where('age < 40')
+ @masters_40_44_men = male_athletes.where('age > 39 and age < 45')
+ @masters_45_49_men = male_athletes.where('age > 44 and age < 50')
+ @masters_50_54_men = male_athletes.where('age > 49 and age < 55')
+ @individual_women = female_athletes.where('age < 40')
+ @masters_40_44_women = female_athletes.where('age > 39 and age < 45')
+ @masters_45_49_women = female_athletes.where('age > 44 and age < 50')
+ @masters_55_59_women = female_athletes.where('age > 54 and age < 60')
end
end

0 comments on commit 96f1874

Please sign in to comment.