noticed
noticed copied to clipboard
NoMethodError (undefined method `notifications'
I m trying to send notification after creating a task and i get this error: NoMethodError (undefined method `notifications' Anyone can help?
You'll have to provide some details.
Hi @excid3, I'm facing the same issue undefined method 'notifications'. Previously things were working perfectly. I just added multi-tenancy using 'act-as-tenant' gem to my models like spam_monitor.
You'll have to add some details. Half an error message isn't much to debug with. 😜
First, thank you @excid3 for this great gem! and your screencast. I watched it a while ago and was looking for an excuse to add it to a project. Now, I have found one.
I also ran into this error message and can provide some details and how I solved it.
I originally ran the rails generate noticed:model and got an error
The name 'Notification' is either already used in your application or reserved by Ruby on Rails. Please choose an alternative or use --skip-collision-check or --force to skip this check and run this generator again.
I have a view_component named Notification, which handles alert/flash messages. I attempted to run the generator with both --skip-collision-check and --force as suggested, but without luck. So, I renamed it to ActivityNotification. I added the has_many association to my User model, but renamed it to :activity_notifications. This is where my mistake was.
I got this error when trying to run OnboardingCompleted.with(contributor: contributor).deliver(current_user).
To solve this, add:
has_many :notifications, as: :recipient, class_name: 'ActivityNotification'
Hope this helps someone.
Thanks @mattwr18. I haven't actually tested much with other model names, so we'll take a look. 👍
I'm going to update the README with these notes but another option if you want to use a custom name for the notification model you can do the following:
rails g noticed:model ActivityNotification
# Then in your `User` model add:
class User < ApplicationRecord
has_many :activity_notifications, as: :recipient
end
# NOTE: If you are using the database delivery method you will need to also add:
class CommentNotification < Noticed::Base
deliver_by :database, association: :activity_notifications
end