# Polymorphic Comment notification to Users?

**URL:** <https://www.ruby-forum.com/t/polymorphic-comment-notification-to-users/172395>\
**Category:** Rails\
**Created:** [July 21, 2009, 12:33am UTC](https://www.ruby-forum.com/t/polymorphic-comment-notification-to-users/172395 "2009-07-21T00:33:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![millisami](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f08c70/32.png) [@millisami](https://www.ruby-forum.com/u/millisami)\
**Post date:** [July 21, 2009, 12:33am UTC](https://www.ruby-forum.com/t/polymorphic-comment-notification-to-users/172395/1 "2009-07-21T00:33:15Z")

</div>

Hi, my webapp has registered users and it has articles, blog posts,  
gossips too.  
For all these resources I’ve a polymorphic Comment model which is  
listed below.

```
id content commentable_id commentable_type user_id
created_at updated_at
    1 Frist comment 2 Article
1 ....
    2 Second comment 3 Post
2 .....
```

So for each commentable resource, I’ve a comment form at the bottom of  
the commentable resource for users to comment.  
I want a checkbox, when checked while submitting the comment, the  
users should receive a notification, be it in Inbox or email since we  
already have it on user signup, when other new comments are added  
later.

I want to have some model like Notifications where I could store the  
commentable\_type, commentable\_id and user\_id (to whom the notification  
should be sent if there is any new comment created with the matching  
commentable and user?

How can I implement the association between Comment and Notification?  
For the checking part if there is any one subscribe to the particular  
commentable resource is create a CommentObserver with after\_create  
hook to initialize the search and send notifications if there is any  
matching record.

But I’m confused what the association, model, controller and views  
would look like to accomplish this? Since the comment model is already  
polymorphic, can I create the Notification model as polymorphic too??
