Class: Decidim::Blogs::Admin::CreatePost
- Inherits:
-
Command
- Object
- Command
- Decidim::Blogs::Admin::CreatePost
- Defined in:
- decidim-blogs/app/commands/decidim/blogs/admin/create_post.rb
Overview
This command is executed when the user creates a Post from the admin panel.
Instance Method Summary collapse
-
#call ⇒ Object
Creates the post if valid.
-
#initialize(form, current_user) ⇒ CreatePost
constructor
A new instance of CreatePost.
Constructor Details
#initialize(form, current_user) ⇒ CreatePost
Returns a new instance of CreatePost.
9 10 11 12 |
# File 'decidim-blogs/app/commands/decidim/blogs/admin/create_post.rb', line 9 def initialize(form, current_user) @form = form @current_user = current_user end |
Instance Method Details
#call ⇒ Object
Creates the post if valid.
Broadcasts :ok if successful, :invalid otherwise.
17 18 19 20 21 22 23 24 25 26 |
# File 'decidim-blogs/app/commands/decidim/blogs/admin/create_post.rb', line 17 def call return broadcast(:invalid) if @form.invalid? transaction do create_post! send_notification end broadcast(:ok, @post) end |