David Kimura PRO
Joined 7/18/2015
Drifting Ruby Owner
Ruby Rogues Panelist
David Kimura PRO said over 3 years ago on Like Relationships and Global ID :
  It looks like we have a bit of mixed up logic here because the post.to_sgid that you're calling is the actual post, not the users_post record.

So, in your destroy action, you would need to have something like this below. This is happening likely because you're on a index action (where you're listing out all of the liked posts) instead of the show action for a particular post like in the episode.

def destroy
  post = Post.friendly.find(params[:post_id])
  user_post = UserPost.find_by(post: post, user: current_user)
  user_post.destroy!
  redirect_to post_path(post), alert: "unfollow"  
end

In this scenario, you're not really doing anything with the signed global id as it's not referring to the actual UserPost.

David Kimura PRO said over 3 years ago on Friend Requests From Scratch :
  Can you share your user model with the relevant bits and the connection model?

David Kimura PRO said over 3 years ago on Friend Requests From Scratch :
Can you also share the contact_request and accept_request methods?

David Kimura PRO said over 3 years ago on Friend Requests From Scratch :
➜  155-friend-requests-from-scratch-master bin/rails c
Loading development environment (Rails 5.2.5)
2.7.3 :001 > user = User.first
  User Load (0.1ms)  SELECT  "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT ?  [["LIMIT", 1]]
 => #<User id: 1, email: "john@example.com", created_at: "2021-04-20 01:30:35", updated_at: "2021-04-20 01:30:35"> 
2.7.3 :002 > user2 = User.last
  User Load (0.3ms)  SELECT  "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT ?  [["LIMIT", 1]]
 => #<User id: 4, email: "eve@example.com", created_at: "2021-04-20 01:30:35", updated_at: "2021-04-20 01:30:35"> 
2.7.3 :003 > user.friend_request(user2)
  Friendship Exists (0.1ms)  SELECT  1 AS one FROM "friendships" WHERE "friendships"."user_id" = ? AND "friendships"."friend_id" = ? LIMIT ?  [["user_id", 1], ["friend_id", 4], ["LIMIT", 1]]
   (0.0ms)  begin transaction
  Friendship Create (0.6ms)  INSERT INTO "friendships" ("user_id", "friend_id", "created_at", "updated_at") VALUES (?, ?, ?, ?)  [["user_id", 1], ["friend_id", 4], ["created_at", "2021-04-20 01:30:59.662695"], ["updated_at", "2021-04-20 01:30:59.662695"]]
  Friendship Create (0.1ms)  INSERT INTO "friendships" ("user_id", "friend_id", "status", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?)  [["user_id", 4], ["friend_id", 1], ["status", 1], ["created_at", "2021-04-20 01:30:59.664399"], ["updated_at", "2021-04-20 01:30:59.664399"]]
   (0.7ms)  commit transaction
 => #<Friendship id: 2, user_id: 4, friend_id: 1, status: "requested", created_at: "2021-04-20 01:30:59", updated_at: "2021-04-20 01:30:59"> 
2.7.3 :004 > 

I downloaded the source and got it running and it still seems to work okay.

You do have two "has_many :connections" defined in the user model which is a bit odd.


David Kimura PRO said over 3 years ago on Friend Requests From Scratch :
In the episode, I was using mysql, so I don't think that's the issue. Are you by chance using Spring? Maybe bin/spring stop and restart your application to see if that helps.