class ScheduleController

Controller for schedule/calendar in different formats. Default to current year if not provided.

Caches all of its pages

Public Instance Methods

calendar() click to toggle source
# File app/controllers/schedule_controller.rb, line 72
def calendar
  expires_in 1.hour, :public => true
  respond_to do |format|
    format.html { render_page }
    format.json {
      events = []
      @events.each do |event|
        events << {:id => event.id, :title => event.full_name, :description => event.full_name, :start => "#{event.date}" , :end => "#{event.end_date}", :allDay => true, :url => "#{event.flyer}"} 
      end
      render :json => events.to_json }
  end
end
index() click to toggle source

Default calendar format

Params

  • year: default to current year

  • discipline

Assigns

# File app/controllers/schedule_controller.rb, line 16
def index
  if mobile_request?
    render :show
  else
    expires_in 1.hour, :public => true
    respond_to do |format|
      format.html { render_page }
      format.rss do
        redirect_to schedule_path(:format => :atom), :status => :moved_permanently
      end
      format.atom
      format.ics do
        send_data(
          RiCal.Calendar do |cal|
            parent_ids = @events.map(&:parent_id).compact.uniq
            multiday_events = MultiDayEvent.where("id in (?) and type = ?", parent_ids, "MultiDayEvent")
            events = @events.reject { |e| multiday_events.include?(e.parent) } + multiday_events
            events.each do |e|
              cal.event do |event|
                event.summary = e.full_name
                event.dtstart =  e.start_date
                event.dtend = e.end_date
                event.location = e.city_state
                event.description = e.discipline
                if e.flyer_approved?
                  event.url = e.flyer
                end
              end
            end
          end,
          :filename => "#{RacingAssociation.current.name} #{@year} Schedule.ics"
        )
      end
      format.xls do
        send_data(CSV.generate(:col_sep => "\t") do |csv|
          csv << [ "id", "parent_id", "date", "name", "discipline", "flyer", "city", "state", "promoter_name" ]
          @events.each do |event|
            csv << [ event.id, event.parent_id, event.date.to_s(:db), event.full_name, event.discipline, event.flyer, event.city, event.state, event.promoter_name ]
          end
        end, :type => :xls)
      end
    end
  end
end
list() click to toggle source

List of events – one line per event

Params

  • year: default to current year

Assigns

# File app/controllers/schedule_controller.rb, line 67
def list
  expires_in 1.hour, :public => true
  render_page
end