Class BarController
In: app/controllers/bar_controller.rb
Parent: ApplicationController

BAR = Best All-around Rider FIXME Add test for overall and make logic cleaner

Methods

categories   index   show  

Public Instance methods

BAR category mappings

[Source]

    # File app/controllers/bar_controller.rb, line 55
55:   def categories
56:     @year = params['year'] || Date.today.year.to_s
57:     date = Date.new(@year.to_i, 1, 1)
58:     @bar = Bar.find(:first, :conditions => ['date = ?', date])
59:     @excluded_categories = Category.find(:all, :conditions => ['parent_id is null'])
60:     expires_in 1.hour, :public => true
61:   end

[Source]

   # File app/controllers/bar_controller.rb, line 6
6:   def index
7:     @overall_bar = OverallBar.find_for_year
8:     expires_in 1.hour, :public => true
9:   end

Default to Overall BAR with links to disciplines

[Source]

    # File app/controllers/bar_controller.rb, line 12
12:   def show
13:     year = params['year'].to_i
14: 
15:     discipline = Discipline[params['discipline']]
16:     if discipline.nil?
17:       flash.now[:warn] = "Could not find discipline \'#{params['discipline']}\'"
18:       return render(:show)
19:     end
20:     
21:     if year < 2007 && discipline == Discipline[:age_graded]
22:       return redirect_to("http://#{RacingAssociation.current.static_host}/bar/#{year}/overall_by_age.html")
23:     elsif year < 2006 && year >= 2001
24:       return redirect_to("http://#{RacingAssociation.current.static_host}/bar/#{year}")
25:     end
26:     
27:     @overall_bar = OverallBar.find_for_year(year)
28:     unless @overall_bar
29:       flash.now[:warn] = "Could not find Overall BAR for #{year}"
30:       return render(:show)
31:     end
32: 
33:     category = @overall_bar.equivalent_category_for(params[:category], discipline)
34:     unless category
35:       flash.now[:warn] = "Could not find BAR category \'#{params['category']}\'"
36:       return render(:show)
37:     end
38:     return redirect_to(:category => category.friendly_param) if category.friendly_param != params["category"]
39:     
40:     @race = @overall_bar.find_race(discipline, category)
41:     unless @race
42:       flash.now[:warn] = "Could not find results"
43:       return render(:show)
44:     end
45:     
46:     # Optimization
47:     @results = Result.find(:all, 
48:                            :include => [ :person, :team ],
49:                            :conditions => [ 'race_id = ?', @race.id ]
50:     ) if @race
51:     expires_in 1.hour, :public => true
52:   end

[Validate]