Class: Decidim::Conferences::Admin::ConferenceSpeakersController

Inherits:
ApplicationController
  • Object
show all
Includes:
Decidim::Conferences::Admin::Concerns::ConferenceAdmin, Paginable
Defined in:
app/controllers/decidim/conferences/admin/conference_speakers_controller.rb

Overview

Controller that allows managing conference speakers.

Instance Method Summary collapse

Instance Method Details

#createObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/decidim/conferences/admin/conference_speakers_controller.rb', line 26

def create
  enforce_permission_to :create, :conference_speaker
  @form = form(ConferenceSpeakerForm).from_params(params)

  CreateConferenceSpeaker.call(@form, current_user, current_conference) do
    on(:ok) do
      flash[:notice] = I18n.t("conference_speakers.create.success", scope: "decidim.admin")
      redirect_to conference_speakers_path(current_conference)
    end

    on(:invalid) do
      flash[:alert] = I18n.t("conference_speakers.create.error", scope: "decidim.admin")
      render :new
    end
  end
end

#destroyObject



67
68
69
70
71
72
73
74
75
76
77
# File 'app/controllers/decidim/conferences/admin/conference_speakers_controller.rb', line 67

def destroy
  @conference_speaker = collection.find(params[:id])
  enforce_permission_to :destroy, :conference_speaker, speaker: @conference_speaker

  DestroyConferenceSpeaker.call(@conference_speaker, current_user) do
    on(:ok) do
      flash[:notice] = I18n.t("conference_speakers.destroy.success", scope: "decidim.admin")
      redirect_to conference_speakers_path(current_conference)
    end
  end
end

#editObject



43
44
45
46
47
# File 'app/controllers/decidim/conferences/admin/conference_speakers_controller.rb', line 43

def edit
  @conference_speaker = collection.find(params[:id])
  enforce_permission_to :update, :conference_speaker, speaker: @conference_speaker
  @form = form(ConferenceSpeakerForm).from_model(@conference_speaker)
end

#indexObject



13
14
15
16
17
18
19
# File 'app/controllers/decidim/conferences/admin/conference_speakers_controller.rb', line 13

def index
  enforce_permission_to :index, :conference_speaker

  @query = params[:q]

  @conference_speakers = paginate(Decidim::Conferences::Admin::ConferenceSpeakers.for(collection, @query))
end

#newObject



21
22
23
24
# File 'app/controllers/decidim/conferences/admin/conference_speakers_controller.rb', line 21

def new
  enforce_permission_to :create, :conference_speaker
  @form = form(ConferenceSpeakerForm).instance
end

#updateObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/decidim/conferences/admin/conference_speakers_controller.rb', line 49

def update
  @conference_speaker = collection.find(params[:id])
  enforce_permission_to :update, :conference_speaker, speaker: @conference_speaker
  @form = form(ConferenceSpeakerForm).from_params(params)

  UpdateConferenceSpeaker.call(@form, @conference_speaker) do
    on(:ok) do
      flash[:notice] = I18n.t("conference_speakers.update.success", scope: "decidim.admin")
      redirect_to conference_speakers_path(current_conference)
    end

    on(:invalid) do
      flash.now[:alert] = I18n.t("conference_speakers.update.error", scope: "decidim.admin")
      render :edit
    end
  end
end