Best Gem and Instructions for setting up followers one way.
Hi Guys,
I have an artist model and I want users to be able to follow them without being followed back. Is there a gem that I can use to do this and is there any documentation on setting that up?
Thanks in advance for any advice.
Gerard
Depending on how your database schema is set up, I'm not sure you'd need a gem to do it. I think, if you create a has_many, through:
association between the artist model and the user model, that should be sufficient.
For example, if you create a new model called followers
then you can add this line to the artist
model:
class Artist < ApplicationRecord
...
has_many :users, through: :followers
end
Similarly on the user
model, you'd say:
class User < ApplicationRecord
...
has_many :artists, through: :followers
end
Finally, on the followers
model, all you say is:
class Follower < ApplicationRecord
belongs_to :artist
belongs_to :user
end
In this way, you can allow a user to 'follow' many artists and allow an artist to have many 'followers' - but unless the artist chooses to also follow a user, it will not happen. (If you want to dis-allow an artist from being able to follow a user, then that can probably be done by removing the 'follow' functionality for artists only within the views or something)
Thanks for this explanation Umar, I will test it out and let you know how I get on.
Thanks,
Gerard