Skip to content

Instantly share code, notes, and snippets.

@ugifractal
Created December 2, 2020 22:38
Show Gist options
  • Save ugifractal/8295f86d29119a450f3644f7b190284c to your computer and use it in GitHub Desktop.
Save ugifractal/8295f86d29119a450f3644f7b190284c to your computer and use it in GitHub Desktop.
Noticed gem error ActiveRecord::RecordInvalid (Validation failed: xxxx must exist):
When sending notification using rails jumpstart and noticed gem I got following error:
NewLead.with(account: Account.first, lead: lead).deliver(User.find(lead.receiver_id))
and got Error performing Noticed::DeliveryMethods::Database (Job ID: 50b96038-e794-4b3b-b9aa-76c400876daa) from Async(default) in 112.37ms: ActiveRecord::RecordInvalid (Validation failed: Account must exist):
This happen because account_id missing on attributes.
Fixed by adding "format" to "deliver_by" at new_lead.rb
# To deliver this notification:
#
# NewLead.with(post: @post).deliver_later(current_user)
# NewLead.with(post: @post).deliver(current_user)
class NewLead < Noticed::Base
# Add your delivery methods
#
deliver_by :database, format: :to_database
deliver_by :action_cable, format: :to_websocket
# deliver_by :email, mailer: "UserMailer"
# deliver_by :slack
# deliver_by :custom, class: "MyDeliveryMethod"
# Add required params
#
param :lead, :account
# Define helper methods to make rendering easier.
#
def message
"You have a new lead"
end
#
def url
lead_path(params[:lead])
end
def to_database
{
account: params.delete(:account) || recipient.personal_account,
type: self.class.name,
params: params
}
end
def to_websocket
{
account: params.delete(:account) || recipient.personal_account,
type: self.class.name,
params: params
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment