title: public activity and Notifications in rails
body: <p>i am designing this little application which consists of Users, Activities,Comments and Notifications.</p>
  
  <p>Users has many activities, Comments and notifications. the Activity was designed following ryan bates tutorial of PublicActivity from scratch <a href="http://railscasts.com/episodes/407-activity-feed-from-scratch" rel="nofollow">407-activity-feed-from-scratch</a>. and also each Activity has many Comments. for the Notifications, it also belongs to the user in such a way that when a Comment is created, a notification is generated, so far my code includes</p>
  
  <p>User Model</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
  
    has_many :comments, :dependent =&gt; :destroy
    has_many :notifications, :dependent =&gt; :destroy
    has_many :activities, :dependent =&gt; :destroy
  
  end  
  
  Activity Model
  
    belongs_to :user
    belongs_to :trackable, polymorphic: true
  
    has_many :comments
    has_many :notifications
    default_scope :order =&gt; "activities.created_at DESC"
    #scope :recent, where(published_at: Time.now - 2.weeks)
  end
  </code></pre>
  
  <p>Comment Model</p>
  
  <pre><code>class Comment &lt; ActiveRecord::Base
    belongs_to :activity
    belongs_to :user
  
    default_scope :order =&gt; "comments.created_at DESC"
  end
  </code></pre>
  
  <p>Notification Model</p>
  
  <pre><code>class Notification &lt; ActiveRecord::Base
    belongs_to :user
    belongs_to :activity
  end
  </code></pre>
  
  <p>in  the controller, </p>
  
  <p>Comments controller i have tried this</p>
  
  <pre><code>def new
      @comment = Comment.new
    end
  
    def create
      @activity = Activity.find(params[:activity_id])
  
      @comment = @activity.comments.create!(comment_params)
      @comment.user = @user
     @comment.save
  
      @users= User.joins(:comments).where(comments: {id:           @activity.comment_ids}).push(@activity.user).uniq_by {|a| a[:user_id]}
      @users.each do |user|
        Notification.create(activity_id:@activity, user_id: user.id)
      end
  
      redirect_to user_path(current_user)
  
    end
  </code></pre>
  
  <p>Activity Controller</p>
  
  <pre><code>def index
      @activities = Activity.all(:include =&gt; :comments, :order =&gt; "created_at DESC")
  
      @comments = Comment.find(:all, :order =&gt; "created_at DESC")
      @comment = Comment.new
      @comment.user = current_user
   end
  </code></pre>
  
  <p>Notification Controller</p>
  
  <pre><code>def index
      @notifications = current_user.notifications
  
   end
  </code></pre>
  
  <p>WHAT I WANT TO ACHIEVE IS, NOTIFICATIONS SHOULD BE Created And Available To:</p>
  
  <ol>
  <li><p>the owner of the activity cos each activity belongs to a particular user i.e when a new comment is created by another user, a notification is available to the owner of the activity.</p></li>
  <li><p>SHOULD NOT! be available to the new commenter i.e the user that as just commented on the activity but available to owner of the activity</p></li>
  <li><p>Available to all previous commenters i.e every user that as commented on that activity
  and the owner of the activity</p></li>
  </ol>
  
  <p>. for now my code above does not work  and also is there anything am doing wrong with the model and controllers?  </p>