mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-01-01 22:17:49 -05:00
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
28 lines
696 B
Ruby
28 lines
696 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Comment < ApplicationRecord
|
|
belongs_to :author, class_name: 'Member', inverse_of: :comments
|
|
belongs_to :post, counter_cache: true
|
|
|
|
scope :post_order, -> { order(created_at: :asc) } # for display on post page
|
|
|
|
after_create do
|
|
recipient = post.author.id
|
|
sender = author.id
|
|
# don't send notifications to yourself
|
|
if recipient != sender
|
|
Notification.create(
|
|
recipient_id: recipient,
|
|
sender_id: sender,
|
|
subject: "#{author} commented on #{post.subject}",
|
|
body:,
|
|
post_id: post.id
|
|
)
|
|
end
|
|
end
|
|
|
|
def to_s
|
|
"#{author.login_name} commented on #{post.subject}"
|
|
end
|
|
end
|