How to tackle this problem: habtm, :though, :as?

Hello peeps,

I currently have the following models:
Users, which can have multiple blog posts, and a Forum with topics and
posts.
So a user can post a blog item, but also a topic/post on the forum

I want to give my users the ability to “watch” a blog post, or a forum
topic, so a little email will be sent when something happens on whatever
they’re watching.

I can’t get my head around a good solution to tackle this problem. I

want to have the possibily to extend my ‘watching’, because in the
future my users want to watch something else, so I was thinking along
the line of :polymorphic, but I can’t get it to work. Any ideas?..

I think you’re on the right track with :polymorphic. However, some sample code would help in diagnosing your problem.


Posted via http://www.ruby-forum.com/.

Michael Guterl

Michael Guterl wrote:

topic, so a little email will be sent when something happens on whatever

they’re watching.

I can’t get my head around a good solution to tackle this problem. I
want to have the possibily to extend my ‘watching’, because in the
future my users want to watch something else, so I was thinking along

the line of :polymorphic, but I can’t get it to work. Any ideas?..

I think you’re on the right track with :polymorphic. However, some
sample
code would help in diagnosing your problem.

Well, I don’t really have any sample code to share, since I am in the
process of trying to set it up. Except for maybe:

Well you mentioned in your earlier post that you tried :polymorphic and it did not work. I was trying to determine “what did not work” with :polymorphic.

class User
has_many :blogposts
has_many :topics
has_many :forumposts

end

class Post
belongs_to :user
end

class Blogpost < Post
end

class ForumPost < Post
end

Check out:

http://blog.hasmanythrough.com/articles/2006/04/03/polymorphic-through

This is the most comprehensive tutorial I have seen or used for polymorphic associations.


Posted via http://www.ruby-forum.com/.

Michael Guterl