add comments on entries

This commit is contained in:
2026-01-23 21:55:54 +01:00
parent b3726e0777
commit 9a814f1aa1
15 changed files with 270 additions and 2 deletions
+31
View File
@@ -0,0 +1,31 @@
class CommentsController < ApplicationController
before_action :require_login
before_action :set_commentable
def create
@comment = @commentable.comments.build(comment_params)
@comment.user = current_user
if @comment.save
respond_to do |format|
format.turbo_stream
format.html { redirect_to @commentable }
end
else
# Handle validation errors
redirect_to @commentable, alert: "Comment could not be created: #{@comment.errors.full_messages.to_sentence}"
end
end
private
def set_commentable
if params[:entry_id]
@commentable = Entry.find(params[:entry_id])
end
end
def comment_params
params.require(:comment).permit(:body, :language_code)
end
end