In this task, we will implement the functionality for users to upvote and downvote posts.
Task 11
- Modify the blog post card component to feature an upvote button, a downvote button and a net vote count. The net vote count should have a value of
upvotes - downvotes
and must dynamically change when a user clicks on the upvote or downvote button. Make sure the upvotes and downvotes values change on the Rails' side as well.
- Each user should be restricted to only one vote.
- Implement the necessary logic to toggle the
is_bloggable
field in the posts table to true
when the net vote count exceeds a defined threshold. If the net vote count falls short of this threshold, please ensure that the is_bloggable
field is set back to false
. To define the constant threshold value, you may use the Rails initializers. If the implementation of this logic ought to be done via some side effects, then you may prefer to opt-in for Active Record callbacks.
- When the
is_bloggable
field is assigned a value of true
, a tag Blog it
must be displayed on the front-end side. For example, if the threshold is set to 40 and the net vote becomes 41, then the tag should be shown as in the figure below.