Class: Decidim::Blogs::Admin::CreatePost

Inherits:
Rectify::Command
  • Object
show all
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

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

#callObject

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