Class: Decidim::Commands::CreateResource
- Inherits:
-
Decidim::Command
- Object
- Decidim::Command
- Decidim::Commands::CreateResource
- Includes:
- ResourceHandler
- Defined in:
- lib/decidim/commands/create_resource.rb
Instance Method Summary collapse
-
#call ⇒ Object
Creates the result if valid.
-
#initialize(form) ⇒ CreateResource
constructor
Initializes the command.
Methods inherited from Decidim::Command
call, #evaluate, #method_missing, #respond_to_missing?, #transaction, #with_events
Constructor Details
#initialize(form) ⇒ CreateResource
Initializes the command.
10 11 12 |
# File 'lib/decidim/commands/create_resource.rb', line 10 def initialize(form) @form = form end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Decidim::Command
Instance Method Details
#call ⇒ Object
Creates the result if valid.
Broadcasts :ok if successful, :invalid otherwise.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/decidim/commands/create_resource.rb', line 17 def call return broadcast(:invalid) if invalid? perform! broadcast(:ok, resource) rescue ActiveRecord::RecordInvalid add_file_attribute_errors! broadcast(:invalid) rescue Decidim::Commands::HookError broadcast(:invalid) end |