Class: EventsController

Inherits:
ApplicationController show all
Defined in:
lib/forge/app/controllers/events_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#app_init

Instance Method Details

#indexObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/forge/app/controllers/events_controller.rb', line 6

def index
  @page_title = 'Listing Events'

  if Forge.config.events.display == :calendar
    now = Time.now

    @year = (params[:year] || now.year).to_i
    @month = (params[:month] || now.month).to_i

    template = 'events/index_calendar'
  else
    # this roundabout sorting is necessary because ruby 1.8
    # doesn't preserve insertion order - sorting and then using
    # group_by doesn't guarantee the items will remain in that order
    @events = Event\
      .published\
      .order('starts_at DESC')\
      .group_by { |e| e.starts_at.strftime('%Y/%m') }\
      .sort_by(&:first)\
      .reverse

    template = 'events/index_list'
  end

  respond_to do |format|
    format.html { render :template => template }
    format.mobile { render :template => 'mobile/events' }
  end
end

#previewObject



46
47
48
49
50
51
52
53
54
55
# File 'lib/forge/app/controllers/events_controller.rb', line 46

def preview
  @event = Event.new(params[:event])
  # call the private methods that cause the timestamps to be set properly
  @event.send(:set_starts_at)
  @event.send(:set_ends_at)
  unless @event.published?
    flash.now[:warning] = "This event is not yet published and will not appear on your live website."
  end
  render :action => :show
end

#showObject



36
37
38
39
40
41
42
43
44
# File 'lib/forge/app/controllers/events_controller.rb', line 36

def show
  @event = Event.find_by_id!(params[:id])
  @page_title = @event.title

  respond_to do |format|
    format.html
    format.mobile { render :template => 'mobile/event' }
  end
end