Files
growstuff/app/views/comments/_comment.html.haml
google-labs-jules[bot] f2421bf4c7 Here's the plan to add polymorphic comments and update related functionality:
This change introduces polymorphic comments, allowing you to comment on Photos, Plantings, Harvests, and Activities, in addition to Posts.

Key changes include:

-   **Comment Model:**
    -   Made `Comment.commentable` a polymorphic association.
    -   Added a data migration to move existing post comments to the new structure.
    -   Updated notification creation logic for polymorphic commentables.
-   **CommentsController:**
    -   Refactored to handle various commentable types using a `find_commentable` method.
-   **Ability Model:**
    -   Updated permissions for comment creation, editing (author/admin), and deletion (author/commentable owner/admin).
-   **Routes:**
    -   Added nested comment routes for Photos, Plantings, Harvests, Activities, and Posts using a `commentable` concern with shallow routes.
-   **Views:**
    -   Created generic partials for comment forms (`_form.html.haml`) and display (`_comment.html.haml`, `_comments.html.haml`).
    -   Integrated these partials into the show pages of all commentable types.
    -   Updated `comments/new` and `comments/edit` views to be generic.
    -   Relevant parent controller `show` actions now eager-load comments.
-   **Testing:**
    -   Added extensive model, controller (using shared examples), and feature tests to cover the new polymorphic comment functionality, including permissions and UI interactions for all commentable types.
    -   Updated and created factories as needed.

This fulfills the issue requirements for adding comments to multiple resource types with appropriate permissions.
2025-05-25 02:03:17 +00:00

37 lines
1.3 KiB
Plaintext

.card.comment
.card-body
.row
.col
= render "members/tiny", member: comment.author
- if can?(:edit, comment) || can?(:destroy, comment)
%hr/
.dropdown
%button#comment-edit-button.btn.dropdown-toggle{"aria-expanded" => "false", "aria-haspopup" => "true", "data-bs-toggle" => "dropdown", type: "button"} Actions
.dropdown-menu.dropdown-menu-xs{"aria-labelledby" => "comment-edit-button"}
- if can? :edit, comment
= link_to edit_comment_path(comment), class: 'dropdown-item' do
= edit_icon
Edit
- if can? :destroy, comment
= link_to comment, method: :delete,
data: { confirm: 'Are you sure?' }, class: 'dropdown-item text-danger' do
= delete_icon
Delete
.col-md-9.border-left
.comment-meta.text-muted
Posted by
- if comment.author.discarded?
Member Deleted
- else
= link_to comment.author.login_name, member_path(comment.author)
on
= comment.created_at
- if comment.updated_at > comment.created_at
and edited at
= comment.updated_at
.comment-body
:markdown
#{ strip_tags markdownify(comment.body) }