Files
fizzy/app/controllers/cards/comments_controller.rb
Jeremy Daer 71a1ee7031 Wrap comment params for flat JSON payloads (#2679)
* Wrap comment params for flat JSON payloads

The SDK sends flat JSON ({"body": "..."}) but Rails wrap_parameters
auto-detection misses :body since it's a virtual ActionText attribute,
not in Comment.attribute_names. Explicitly declare wrap_parameters so
params.expect(comment: [...]) works with both wrapped and flat payloads.

* Test comment create and update with flat JSON params
2026-03-09 17:02:08 -07:00

63 lines
1.3 KiB
Ruby

class Cards::CommentsController < ApplicationController
wrap_parameters :comment, include: %i[ body created_at ]
include CardScoped
before_action :set_comment, only: %i[ show edit update destroy ]
before_action :ensure_creatorship, only: %i[ edit update destroy ]
before_action :ensure_card_is_commentable, only: :create
def index
set_page_and_extract_portion_from @card.comments.chronologically
end
def create
@comment = @card.comments.create!(comment_params)
respond_to do |format|
format.turbo_stream
format.json { render :show, status: :created, location: card_comment_path(@card, @comment, format: :json) }
end
end
def show
end
def edit
end
def update
@comment.update! comment_params
respond_to do |format|
format.turbo_stream
format.json { head :no_content }
end
end
def destroy
@comment.destroy
respond_to do |format|
format.turbo_stream
format.json { head :no_content }
end
end
private
def set_comment
@comment = @card.comments.find(params[:id])
end
def ensure_creatorship
head :forbidden if Current.user != @comment.creator
end
def ensure_card_is_commentable
head :forbidden unless @card.commentable?
end
def comment_params
params.expect(comment: [ :body, :created_at ])
end
end