Class: Decidim::Votings::Admin::CreateBallotStyle
- Inherits:
-
Command
- Object
- Command
- Decidim::Votings::Admin::CreateBallotStyle
- Defined in:
- app/commands/decidim/votings/admin/create_ballot_style.rb
Overview
A command with the business logic to create the ballot style
Instance Method Summary collapse
-
#call ⇒ Object
Executes the command.
-
#initialize(form) ⇒ CreateBallotStyle
constructor
A new instance of CreateBallotStyle.
Constructor Details
#initialize(form) ⇒ CreateBallotStyle
Returns a new instance of CreateBallotStyle.
8 9 10 |
# File 'app/commands/decidim/votings/admin/create_ballot_style.rb', line 8 def initialize(form) @form = form end |
Instance Method Details
#call ⇒ Object
Executes the command. Broadcast this events:
-
:ok when everything is valid
-
:invalid when the form was not valid and could not proceed
Returns nothing.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/commands/decidim/votings/admin/create_ballot_style.rb', line 17 def call return broadcast(:invalid) unless form.valid? begin create_ballot_style! rescue ActiveRecord::RecordNotUnique form.errors.add(:code, :taken) return broadcast(:invalid) end create_ballot_style_questions! broadcast(:ok) end |