Commit d04d12b0 authored by Vanessa Silva's avatar Vanessa Silva
Browse files

Matches create fixed

parent db6ee624
Pipeline #41782 failed with stage
in 51 seconds
...@@ -4,7 +4,11 @@ class LikesController < ApplicationController ...@@ -4,7 +4,11 @@ class LikesController < ApplicationController
if @like.save if @like.save
flash[:notice] = 'Like successful' flash[:notice] = 'Like successful'
create_match if likes_mutually
got_liked_user = User.find_by(id: like_params[:liked_user_id])
like_exists = Like.exists?(liked_user_id: current_user.id, user_id: got_liked_user.id)
Match.create(user_one: got_liked_user, user_two: current_user) if like_exists
redirect_to root_path redirect_to root_path
else else
...@@ -16,18 +20,6 @@ class LikesController < ApplicationController ...@@ -16,18 +20,6 @@ class LikesController < ApplicationController
private private
def got_liked_user
User.find_by(id: like_params[:liked_user_id])
end
def create_match
Match.create(user_one: got_liked_user, user_two: current_user)
end
def likes_mutually
true if got_liked_user.liked_users.include?(current_user)
end
def like_params def like_params
params.require(:like).permit(:user_id, :liked_user_id) params.require(:like).permit(:user_id, :liked_user_id)
end end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment