Files
growstuff/app/controllers/comments_controller.rb
google-labs-jules[bot] 4b9763e1da feat: Add problem tracking feature
This commit introduces a new `Problem` model, analogous to `Crop`, to allow users to track problems they have on their plantings (e.g., aphids on tomatoes).

Key features:
- A new `Problem` model that can be curated by admins (`problem_wranglers`).
- Users can associate problems with their plantings and upload photos of the problems.
- Aggregated problem information is displayed on the crop detail page (e.g., "Problems: aphids (27), blight (13)").
- Users can mention problems in posts (e.g., `[aphids](problem)`), which automatically links to the problem's page.
- Admin functionality for reviewing and approving new problem suggestions.

Resolves merge conflict in app/controllers/plantings_controller.rb
2025-09-07 11:47:53 +00:00

56 lines
1.2 KiB
Ruby

# frozen_string_literal: true
class CommentsController < ApplicationController
before_action :authenticate_member!, except: %i(index)
load_and_authorize_resource
respond_to :html, :json
respond_to :rss, only: :index
responders :flash
def index
@comments = Comment.order(created_at: :desc).paginate(page: params[:page])
respond_with(@comments)
end
def new
@comment = Comment.new
@post = Post.find_by(id: params[:post_id])
if @post
@comments = @post.comments
respond_with(@comments)
else
redirect_to(request.referer || root_url,
alert: "Can't post a comment on a non-existent post")
end
end
def edit
@comments = @comment.post.comments
end
def create
@comment = Comment.new(comment_params)
@comment.author = current_member
@comment.save
respond_with @comment, location: @comment.post
end
def update
@comment.update(body: comment_params['body'])
respond_with @comment, location: @comment.post
end
def destroy
@post = @comment.post
@comment.destroy
respond_with(@post)
end
private
def comment_params
params.require(:comment).permit(:body, :post_id)
end
end