Files
fizzy/app/controllers/comments_controller.rb
T
David Heinemeier Hansson 8ff017fc5b Only one invocation of this, not carrying the worth of its indirection
Generally I am wary of including global state checks in the belly of
models. It is one thing to do it as a default parameter, but I think it
is too far to do it inside an actual method.
2025-04-05 12:40:08 +02:00

44 lines
875 B
Ruby

class CommentsController < ApplicationController
include BubbleScoped, BucketScoped
before_action :set_comment, only: [ :show, :edit, :update, :destroy ]
before_action :require_own_comment, only: [ :edit, :update, :destroy ]
def create
@bubble.capture new_comment
end
def show
end
def edit
end
def update
@comment.update! comment_params
end
def destroy
@comment.destroy
redirect_to @bubble
end
private
def comment_params
params.require(:comment).permit(:body)
end
def new_comment
Comment.new(comment_params)
end
def set_comment
@comment = Comment.joins(:message)
.where(messages: { bubble_id: @bubble.id })
.find(params[:id])
end
def require_own_comment
head :forbidden unless Current.user == @comment.creator
end
end