Class: Calagator::EventsController

Inherits:
ApplicationController show all
Includes:
DuplicateChecking::ControllerActions
Defined in:
app/controllers/calagator/events_controller.rb

Instance Method Summary collapse

Methods included from DuplicateChecking::ControllerActions

#duplicates, #squash_many_duplicates

Methods inherited from ApplicationController

#recaptcha_enabled?

Instance Method Details

#cloneObject



105
106
107
108
109
# File 'app/controllers/calagator/events_controller.rb', line 105

def clone
  @event = Event::Cloner.clone(Event.find(params[:id]))
  flash[:success] = 'This is a new event cloned from an existing one. Please update the fields, like the time and description.'
  render 'new'
end

#createObject

POST /events POST /events.xml



46
47
48
49
# File 'app/controllers/calagator/events_controller.rb', line 46

def create
  @event = Event.new
  create_or_update
end

#create_or_updateObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/controllers/calagator/events_controller.rb', line 57

def create_or_update
  saver = Event::Saver.new(@event, params.permit!)
  respond_to do |format|
    if recaptcha_verified?(@event) && saver.save
      format.html do
        flash[:success] = 'Event was successfully saved.'
        if saver.has_new_venue?
          flash[:success] += " Please tell us more about where it's being held."
          redirect_to edit_venue_url(@event.venue, from_event: @event.id)
        else
          redirect_to @event
        end
      end
      format.xml  { render xml: @event, status: :created, location: @event }
    else
      format.html do
        flash[:failure] = saver.failure
        render action: @event.new_record? ? 'new' : 'edit'
      end
      format.xml { render xml: @event.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /events/1 DELETE /events/1.xml



83
84
85
86
87
88
89
90
# File 'app/controllers/calagator/events_controller.rb', line 83

def destroy
  @event.destroy

  respond_to do |format|
    format.html { redirect_to(events_url, flash: { success: "\"#{@event.title}\" has been deleted" }) }
    format.xml  { head :ok }
  end
end

#editObject

GET /events/1/edit



42
# File 'app/controllers/calagator/events_controller.rb', line 42

def edit; end

#indexObject

GET /events GET /events.xml



17
18
19
20
21
22
# File 'app/controllers/calagator/events_controller.rb', line 17

def index
  @browse = Event::Browse.new(params)
  @events = @browse.events
  @browse.errors.each { |error| append_flash :failure, error }
  render_events @events
end

#newObject

GET /events/new GET /events/new.xml



37
38
39
# File 'app/controllers/calagator/events_controller.rb', line 37

def new
  @event = Event.new(params.permit![:event])
end

#searchObject

GET /events/search



93
94
95
96
97
98
99
100
101
102
103
# File 'app/controllers/calagator/events_controller.rb', line 93

def search
  @search = Event::Search.new(params)

  # setting @events so that we can reuse the index atom builder
  @events = @search.events

  flash[:failure] = @search.failure_message
  return redirect_to root_path if @search.hard_failure?

  render_events(@events)
end

#showObject

GET /events/1 GET /events/1.xml



26
27
28
29
30
31
32
33
# File 'app/controllers/calagator/events_controller.rb', line 26

def show
  @event = Event.find(params[:id])
  return redirect_to(@event.originator) if @event.duplicate?

  render_event @event
rescue ActiveRecord::RecordNotFound => e
  redirect_to events_path, flash: { failure: e.to_s }
end

#updateObject

PUT /events/1 PUT /events/1.xml



53
54
55
# File 'app/controllers/calagator/events_controller.rb', line 53

def update
  create_or_update
end