New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to block users from following other models? #43
Comments
You'd implement a check on the follow method for both models that checks the ID of the follower (the person making the request) against a block list owned by the followee (the person the follower is requesting to follow). The block list in this example is done with a database table, but you could use a text file, a YAML file, Redis, etc. depending on your requirements. The following code is just a sample: you'll need to modify it accordingly. # example follow method
def follow(resource)
unless current_user.is_blocked?(resource)
current_user.follow!(resource)
else
puts "You can't follow this resource!"
end
end
# this method goes in both models
def is_blocked?(resource)
blocked = BlockList.where(blocker_id: resource.id, blocked_id: current_user.id).first
if blocked then
return true
else
return false
end
end |
I added the follow method that you gave me to the follow model, and I added the is_blocked method to the normal user and business model. I will probably render a view instead of showing the puts statement to provide better styling. On another note, can you try to create a sample application, I can't seem to find the one that you've posted before. I just want to understand the entire structure of the gem, so that I can maybe extend it later. |
Hi, my apologies for not seeing this sooner: I'm rarely on GitHub these days. The code I provided was just something I typed up (adapted from a client project); I don't have a sample application yet (but I could create one). The best way to understand the structure of the gem is to read the source files for it. |
You've done an awesome job with the gem. I just like to be 100% in the know with best practices for it. If you can build a bare-bones sample project. That would be nice. Thank you. |
I didn't create this gem :) |
I have two models in my project. One for businesses and one for normal users. How would I be able to give businesses/users the ability to block each other?
The text was updated successfully, but these errors were encountered: