title: Ruby on Rails - Follower notification using noticed
body: <p>My goal is to display in the notifications modal that a follower has started following the current user whenever the  user clicks the follow button.
  I am also using the noticed gem, but it seems a bit complicated for me to implement with my relationship model (Which is the follower/following model).</p>
  <p>Whenever I follow someone, I see in the console that it is inserting the notification, but when I click unfollow I get an error that there are &quot;too many has_many associations&quot;. And when I log in as the user that gets followed the notification does not appear. I am assuming because I have implemented the notify recipient function wrong.And I cannot seem to find any resources only for follow notifications.</p>
  <p>Here is my code:</p>
  <p>FollowNotification.rb</p>
  <pre><code>def message
      @user = User.find(follower_id: params[:user_id])
      &quot;#{@user.username} has started following you&quot;
    end
    #
    def url
      show_user_path(@user)
    end
  </code></pre>
  <p>Relationships Controller</p>
  <pre><code>class RelationshipsController &lt; ApplicationController
      before_action :authenticate_user!
  
      def create
          @user = User.find(params[:user_id])
          # if statement prevents user from forcing both users to follow each other after accepting request
          if current_user.Is_private? &amp;&amp; !@user.pending_requests
              following = @user.relationships.build(follower_id: current_user.id)
              following.save
              redirect_to request.referrer || root_path
          else
              following = current_user.relationships.build(follower_id: params[:user_id])
              following.save
              redirect_to request.referrer || root_path
          end
      end
  
      def destroy
          following = current_user.relationships.find_by(follower_id: params[:user_id])
          following.destroy
          redirect_to request.referrer || root_path
      end
  end
  </code></pre>
  <p>Relationship model</p>
  <pre><code>class Relationship &lt; ApplicationRecord
      belongs_to :following, class_name: 'User'
      belongs_to :follower, class_name: 'User'
      has_noticed_notifications model_name: 'Notification'
      has_many :notifications, through: :user, dependent: :destroy
  
      after_create_commit :notify_recipient
      before_destroy :cleanup_notifications
  
      private
      def notify_recipient
          FollowNotification.with(follower: self).deliver_later(following.id)
        end
  
      def cleanup_notifications
          notifications_as_follow.destroy_all
      end
  
  end
  </code></pre>
  <p>User model</p>
  <pre><code>class User &lt; ApplicationRecord
    has_merit
  
    devise :database_authenticatable, :registerable,
           :recoverable, :rememberable, :validatable
  
    has_one_attached :avatar
  
    validates :avatar, file_size: { less_than_or_equal_to: 5.megabytes },
                file_content_type: { allow: ['image/jpg', 'image/png', 'image/jpeg'] }
  
    has_many(
      :posts,
      class_name: 'Post',
      foreign_key: 'user_id',
      inverse_of: :user
    )
  
    has_many :likes
  
    has_many :comments
  
    validates :username, presence: true, length: {maximum: 30}
    validates_uniqueness_of :username
  
    has_many :relationships, foreign_key: :following_id
    has_many :followings, through: :relationships, source: :follower
  
    has_many :reverse_of_relationships, class_name: 'Relationship', foreign_key: :follower_id
    has_many :followers, through: :reverse_of_relationships, source: :following
  
    def is_followed?(user)
      reverse_of_relationships.find_by(following_id: user.id).present?
    end
  
    has_many :notifications, as: :recipient, dependent: :destroy
  end
  </code></pre>