Allow group admins to pin posts to their groups.
For a social media platform built with Rails, using Turbo and Stimulus.
It was possible to pin a post to the top of a group feed, but only via the backend/ActiveAdmin interface. The goal was for a group admin to be able to pin and unpin posts directly from the group feed.
To do this:
For a social media platform built with Rails, using Turbo and Stimulus.
It was possible to pin a post to the top of a group feed, but only via the backend/ActiveAdmin interface. The goal was for a group admin to be able to pin and unpin posts directly from the group feed.
To do this:
- Add toggle function to relevant controller
- Update routes file for new controller method
- Update view partials in several places, grabbing a check for whether a user is a group admin and if so, allowing the addition of a "Pin this post" link to posts in their group.
- Utilize ternary to change text of link to "Pin this post" or "Unpin this post" depending on status of the post's pinned boolean.