Class: Editor::EventsController

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

Overview

This controller manage Event model for editors

Instance Method Summary collapse

Methods inherited from ApplicationController

#default_url_options, #new_session_path

Instance Method Details

#createObject

POST /editor/events



31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/editor/events_controller.rb', line 31

def create
  @event = Event.new(event_params)
  if @event.save
    @status = { success: "Evento creato" }
    redirect_to editor_event_path(@event)
  else
    @status = { error: "ERRORE - Evento non creato. Verifica gli errori." }
    render action: :new
  end
end

#destroyObject

DELETE /editor/events/:id



54
55
56
57
58
59
60
61
62
# File 'app/controllers/editor/events_controller.rb', line 54

def destroy
  if @event.destroy
    @status = { success: "Evento eliminato" }
    redirect_to editor_events_path
  else
    @status = { error: "ERRORE - Evento non eliminato. Verifica gli errori." }
    render action: :edit
  end
end

#editObject

GET /editor/events/:id/edit



28
# File 'app/controllers/editor/events_controller.rb', line 28

def edit; end

#indexObject

GET /editor/events



10
11
12
13
14
15
16
17
# File 'app/controllers/editor/events_controller.rb', line 10

def index
  @categories = @groups.pluck :title, :id
  from     = filter_params[:from]
  to       = filter_params[:to]
  group_id = @groups.exists?(filter_params[:category]) ? filter_params[:category] : @groups.pluck(:id)
  text     = filter_params[:text]
  @pagy, @events = pagy(Event.searchable(from:, to:, group_id:, text:, editor: true, reserved: true), items: 6)
end

#newObject

GET /editor/events/new



23
24
25
# File 'app/controllers/editor/events_controller.rb', line 23

def new
  @event = Event.new
end

#showObject

GET /editor/events/:id



20
# File 'app/controllers/editor/events_controller.rb', line 20

def show; end

#updateObject

PATCH/PUT /editor/events/:id



43
44
45
46
47
48
49
50
51
# File 'app/controllers/editor/events_controller.rb', line 43

def update
  if @event.update(event_params)
    @status = { success: "Evento Aggiornato" }
    render action: :show
  else
    @status = { error: "ERRORE - Evento non aggiornato. Verifica gli errori." }
    render :edit
  end
end