Class: CoPlan::CommentsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/coplan/comments_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

controller_path

Instance Method Details

#createObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/coplan/comments_controller.rb', line 6

def create
  authorize!(@plan, :show?)

  comment = @thread.comments.create!(
    author_type: "human",
    author_id: current_user.id,
    body_markdown: params[:comment][:body_markdown]
  )

  Broadcaster.append_to(
    @plan,
    target: ActionView::RecordIdentifier.dom_id(@thread, :comments),
    partial: "coplan/comments/comment",
    locals: { comment: comment }
  )

  # The broadcast above updates all clients (including the submitter) via WebSocket.
  # The empty turbo_stream response prevents Turbo from navigating (which causes scroll-to-top).
  respond_to do |format|
    format.turbo_stream { render turbo_stream: [] }
    format.html { redirect_to plan_path(@plan), notice: "Reply added." }
  end
end