Class: Decidim::Elections::Admin::ElectionsController
- Inherits:
-
ApplicationController
- Object
- Admin::Components::BaseController
- ApplicationController
- Decidim::Elections::Admin::ElectionsController
- Defined in:
- app/controllers/decidim/elections/admin/elections_controller.rb
Overview
This controller allows the create or update an election.
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #publish ⇒ Object
- #unpublish ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/controllers/decidim/elections/admin/elections_controller.rb', line 19 def create :create, :election @form = form(ElectionForm).from_params(params, current_component:) CreateElection.call(@form) do on(:ok) do flash[:notice] = I18n.t("elections.create.success", scope: "decidim.elections.admin") redirect_to elections_path end on(:invalid) do flash.now[:alert] = I18n.t("elections.create.invalid", scope: "decidim.elections.admin") render action: "new" end end end |
#destroy ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'app/controllers/decidim/elections/admin/elections_controller.rb', line 58 def destroy (:delete, :election, election:) DestroyElection.call(election, current_user) do on(:ok) do flash[:notice] = I18n.t("elections.destroy.success", scope: "decidim.elections.admin") end on(:invalid) do flash[:alert] = I18n.t("elections.destroy.invalid", scope: "decidim.elections.admin") end end redirect_to elections_path end |
#edit ⇒ Object
36 37 38 39 |
# File 'app/controllers/decidim/elections/admin/elections_controller.rb', line 36 def edit (:update, :election, election:) @form = form(ElectionForm).from_model(election) end |
#index ⇒ Object
10 11 12 |
# File 'app/controllers/decidim/elections/admin/elections_controller.rb', line 10 def index flash.now[:alert] ||= I18n.t("elections.index.no_bulletin_board", scope: "decidim.elections.admin").html_safe unless Decidim::Elections.bulletin_board.configured? end |
#new ⇒ Object
14 15 16 17 |
# File 'app/controllers/decidim/elections/admin/elections_controller.rb', line 14 def new :create, :election @form = form(ElectionForm).instance end |
#publish ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'app/controllers/decidim/elections/admin/elections_controller.rb', line 74 def publish (:publish, :election, election:) PublishElection.call(election, current_user) do on(:ok) do flash[:notice] = I18n.t("admin.elections.publish.success", scope: "decidim.elections") redirect_to elections_path end end end |
#unpublish ⇒ Object
85 86 87 88 89 90 91 92 93 94 |
# File 'app/controllers/decidim/elections/admin/elections_controller.rb', line 85 def unpublish (:unpublish, :election, election:) UnpublishElection.call(election, current_user) do on(:ok) do flash[:notice] = I18n.t("admin.elections.unpublish.success", scope: "decidim.elections") redirect_to elections_path end end end |
#update ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/controllers/decidim/elections/admin/elections_controller.rb', line 41 def update (:update, :election, election:) @form = form(ElectionForm).from_params(params, current_component:) UpdateElection.call(@form, election) do on(:ok) do flash[:notice] = I18n.t("elections.update.success", scope: "decidim.elections.admin") redirect_to elections_path end on(:invalid) do flash.now[:alert] = I18n.t("elections.update.invalid", scope: "decidim.elections.admin") render action: "edit" end end end |