David Kimura PRO
Joined 7/18/2015
Drifting Ruby Owner
David Kimura PRO said about 5 years ago on Creating and Reading QR Codes :
A QR code is really just an encoded text. There isn't really any kind of data structure to it. So it can have text like the product name or a URL to it.

David Kimura PRO said about 5 years ago on Like Relationships and Global ID :
  Do you have the associations in your models?

  has_many :users_posts
  has_many :liked_posts, through: :users_posts, source: :post

You can then call user.liked_posts on your instance of the user.

David Kimura PRO said about 5 years ago on Like Relationships and Global ID :
  you're looping through all of the liked posts, so you would need to call post.to_sgid instead of @liked_post.to_sgid

David Kimura PRO said about 5 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 about 5 years ago on Friend Requests From Scratch :
  Can you share your user model with the relevant bits and the connection model?