Adding a “Like/Unlike” button to a post in Rails

前端 未结 4 2029
陌清茗
陌清茗 2021-02-04 22:34

The site is a simple community where each user creates posts and users may \"like\" them or \"unlike\" them.

I have a Post and a Like model. Currently, I\'m listing all

4条回答
  •  南笙
    南笙 (楼主)
    2021-02-04 23:02

    create an action like this in your posts controller.

    def unlike
       # get the post
       #code to decrement the like counter of a specific post
    end
    

    then from your view, create a button or a link that points to this action.

提交回复
热议问题