Last active
July 16, 2020 12:25
-
-
Save dgorodnichy/c013cef8081b3adf22c5ba538214c6bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Api | |
class LikesController < ApplicationController | |
def update | |
@user = User.find(params['user_id']) | |
@post = Post.find(params['post_id']) | |
like = @post.likes.find_or_initialize_by(user: @user) | |
if like.persisted? | |
like.destroy! | |
render json: { isLiked: false } | |
else | |
like.save! | |
render json: { isLiked: true } | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment