Class: Decidim::Initiatives::InitiativeVotesController
- Inherits:
-
ApplicationController
- Object
- DecidimController
- ApplicationController
- ApplicationController
- Decidim::Initiatives::InitiativeVotesController
- Includes:
- FormFactory, NeedsInitiative
- Defined in:
- decidim-initiatives/app/controllers/decidim/initiatives/initiative_votes_controller.rb
Overview
Exposes the initiative vote resource so users can vote initiatives.
Instance Method Summary collapse
-
#create ⇒ Object
POST /initiatives/:initiative_id/initiative_vote.
-
#destroy ⇒ Object
DELETE /initiatives/:initiative_id/initiative_vote.
Methods inherited from ApplicationController
#permission_class_chain, #permission_scope, #permissions_context
Methods included from RegistersPermissions
Methods included from UserBlockedChecker
#check_user_block_status, #check_user_not_blocked
Methods included from NeedsSnippets
Methods included from Headers::HttpCachingDisabler
Methods included from HasStoredPath
#skip_store_location?, #store_current_location
Methods included from NeedsOrganization
enhance_controller, extended, included
Instance Method Details
#create ⇒ Object
POST /initiatives/:initiative_id/initiative_vote
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'decidim-initiatives/app/controllers/decidim/initiatives/initiative_votes_controller.rb', line 15 def create :vote, :initiative, initiative: current_initiative @form = form(Decidim::Initiatives::VoteForm).from_params( initiative: current_initiative, signer: current_user ) VoteInitiative.call(@form) do on(:ok) do current_initiative.reload render :update_buttons_and_counters end on(:invalid) do render json: { error: I18n.t("initiative_votes.create.error", scope: "decidim.initiatives") }, status: :unprocessable_entity end end end |
#destroy ⇒ Object
DELETE /initiatives/:initiative_id/initiative_vote
38 39 40 41 42 43 44 45 46 47 |
# File 'decidim-initiatives/app/controllers/decidim/initiatives/initiative_votes_controller.rb', line 38 def destroy :unvote, :initiative, initiative: current_initiative UnvoteInitiative.call(current_initiative, current_user) do on(:ok) do current_initiative.reload render :update_buttons_and_counters end end end |