views:

161

answers:

2

I have a site with a tagging system but would like to enable users to be able to subscribe to different sets of tags of their choice so that when a new submission is made and has tags that match what the user is subscribed to they get a notification. For example, say a user is only interested in red, wallpapers that are considered large. They would add those three tags to a set and when a wallpaper is added that contains those tags the user gets a notification. They would need to be able to do this with any set of tags. It seems like a tricky problem, and I can't seem to come up with a simple solution. Does anyone know if this is already solved in a Gem somewhere, or have any ideas on how to do it efficiently?

Thanks for looking

+1  A: 

You can make User model taggable also:

# User model
acts_as_taggable

And add user selected tags to their User object: @user.tag ['wallpapers', 'red', 'large'] And then in model for which you want notifications add:

after_create :send_notifications

def send_notifications
  @users = User.find_tagged_with :all => self.tag_names
  @users.each do |u|
    something_that_will_send_notification_to_user u
  end
end
klew
This is a good start, but what if users have multiple tag collections. For example, they may have wallpapers, red, large as one set they're monitoring and photograph, nature, large as another set. Would this be possible to do?
jklina
If you want to add tag sets, then probably you need to add another model, `UserTagSet`, to which you can add `acts_as_taggable` and `belongs_to :user`. Then in User remove `acts_as_taggable` and add `has_many :user_tag_sets`. Then you can add many tag sets to a single user and you can do `UserTagSet.find_tagged_with :all => self.tag_names`. From this you can get users who should be noticed. Does it give you a clue, or should I add more example code?
klew