We've moved discussions to Discord

Do I Need Account with Notifications?

Ryan Chin
I'm expecting my notifications to be relevant to users, not accounts.  What happens if I remove the requirement for Account from Notifications?  I'm trying to understand why it's in there.

I'm trying to implement Notifications, but I'm getting "ActiveRecord::RecordInvalid: Validation failed: Account must exist".  

my model:

class NewFan < Noticed::Base  deliver_by :database
  # Add required params  
    param :fan


  # Define helper methods to make rendering easier.  #  
  def message    
    "You have a new fan" 
  end  #  
 
  def url    
    fan_path(params[:fan])  
  end

end

From the console I'm running:
NewFan.with(fan: @fan).deliver(User.where(id: @fan.fan_id)

Even though the documentation doesn't say anything about having to pass in account_id or account (https://jumpstartrails.com/docs/notifications), I saw this post and so I changed:
param :fan to param :fan, :account

And ran:
NewFan.with(fan: @fan, account: @account).deliver(User.where(id: @fan.fan_id)


Yet, I still get the same error (even when I specify an account that exists).  Can someone please help me figure out what I'm doing wrong?



Full trace:
[1] pry(main)> @fan = Fan.find(43)
  Fan Load (2.7ms)  SELECT "fans".* FROM "fans" WHERE "fans"."id" = $1 LIMIT $2  [["id", 43], ["LIMIT", 1]]
=> #<Fan:0x00007fffc4fb4fe8
 id: 43,
 first_name: "Test",
 last_name: "Test",
 phone: "",
 email: "",
 exclusive: false,
 created_at: Tue, 01 Dec 2020 05:16:37 UTC +00:00,
 updated_at: Tue, 01 Dec 2020 05:16:37 UTC +00:00,
 user_id: 19,
 looking_for: "hi",
 know_you: "hi",
 receiver_id: 14,
 status: "New",
 notes: nil,
 city: "NYC",
 state: "NY",
 latitude: 0.407127281e2,
 longitude: -0.740060152e2,
 country: nil>
[2] pry(main)> @account = Account.find(14)
  Account Load (2.2ms)  SELECT "accounts".* FROM "accounts" WHERE "accounts"."id" = $1 LIMIT $2  [["id", 14], ["LIMIT", 1]]
=> #<Account:0x00007f9af892cc60
 id: 14,
 name: "Kermit the Frog",
 owner_id: 14,
 personal: false,
 created_at: Thu, 26 Nov 2020 03:30:26 UTC +00:00,
 updated_at: Thu, 26 Nov 2020 03:30:26 UTC +00:00,
 processor: nil,
 processor_id: nil,
 trial_ends_at: nil,
 card_type: nil,
 card_last4: nil,
 card_exp_month: nil,
 card_exp_year: nil,
 extra_billing_info: nil,
 domain: nil,
 subdomain: nil,
 plan: nil,
 quantity: nil,
 card_token: nil>
[3] pry(main)> NewFan.with(fan: @fan, account: @account).deliver(User.where(id: @fan.receiver_id))
  User Load (5.2ms)  SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2  [["id", 19], ["LIMIT", 1]]
Performing Noticed::DeliveryMethods::Database (Job ID: 964dfa37-4f11-4233-92db-5065ff8e54ef) from Async(default) enqueued at  with arguments: {:notification_class=>"NewFan", :options=>{}, :params=>{:fan=>#<GlobalID:0x00007f9ae3d0e988 @uri=#<URI::GID gid://jumpstart-app/Fan/43>>, :account=>#<GlobalID:0x00007f9ae3d0e320 @uri=#<URI::GID gid://jumpstart-app/Account/14>>}, :recipient=>#<GlobalID:0x00007f9ae3d0dc90 @uri=#<URI::GID gid://jumpstart-app/User/14>>, :record=>nil}
  Fan Load (0.7ms)  SELECT "fans".* FROM "fans" WHERE "fans"."id" = $1 LIMIT $2  [["id", 43], ["LIMIT", 1]]
  Account Load (0.6ms)  SELECT "accounts".* FROM "accounts" WHERE "accounts"."id" = $1 LIMIT $2  [["id", 14], ["LIMIT", 1]]
Error performing Noticed::DeliveryMethods::Database (Job ID: b6c0ae9a-3d87-4a16-bb09-71eafb5a60a5) from Async(default) in 50.59ms: ActiveRecord::RecordInvalid (Validation failed: Account must exist):
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/validations.rb:80:in `raise_validation_error'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/validations.rb:53:in `save!'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/transactions.rb:318:in `block in save!'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/transactions.rb:375:in `block in with_transaction_returning_status'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract/database_statements.rb:278:in `transaction'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/transactions.rb:212:in `transaction'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/transactions.rb:366:in `with_transaction_returning_status'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/transactions.rb:318:in `save!'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/suppressor.rb:48:in `save!'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/associations/collection_association.rb:360:in `insert_record'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/associations/has_many_association.rb:36:in `insert_record'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/associations/collection_association.rb:347:in `block (2 levels) in _create_record'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/associations/collection_association.rb:447:in `replace_on_target'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/associations/collection_association.rb:285:in `add_to_target'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/associations/collection_association.rb:346:in `block in _create_record'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/associations/collection_association.rb:135:in `block in transaction'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract/database_statements.rb:280:in `block in transaction'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract/transaction.rb:280:in `block in within_new_transaction'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract/transaction.rb:278:in `within_new_transaction'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/connection_adapters/abstract/database_statements.rb:280:in `transaction'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/transactions.rb:212:in `transaction'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/associations/collection_association.rb:134:in `transaction'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/associations/collection_association.rb:344:in `_create_record'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/associations/has_many_association.rb:115:in `_create_record'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/associations/association.rb:199:in `create!'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/associations/collection_proxy.rb:363:in `create!'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/noticed-1.2.20/lib/noticed/delivery_methods/database.rb:6:in `deliver'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/noticed-1.2.20/lib/noticed/delivery_methods/base.rb:47:in `block in perform'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/callbacks.rb:101:in `run_callbacks'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/noticed-1.2.20/lib/noticed/delivery_methods/base.rb:46:in `perform'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activejob-6.0.3.1/lib/active_job/execution.rb:40:in `block in perform_now'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/callbacks.rb:112:in `block in run_callbacks'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/i18n-1.8.2/lib/i18n.rb:308:in `with_locale'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activejob-6.0.3.1/lib/active_job/translation.rb:9:in `block (2 levels) in <module:Translation>'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/callbacks.rb:121:in `instance_exec'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/callbacks.rb:121:in `block in run_callbacks'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/core_ext/time/zones.rb:66:in `use_zone'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activejob-6.0.3.1/lib/active_job/timezones.rb:9:in `block (2 levels) in <module:Timezones>'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/callbacks.rb:121:in `instance_exec'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/callbacks.rb:121:in `block in run_callbacks'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activejob-6.0.3.1/lib/active_job/logging.rb:25:in `block (4 levels) in <module:Logging>'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/notifications.rb:180:in `block in instrument'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/notifications.rb:180:in `instrument'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activejob-6.0.3.1/lib/active_job/logging.rb:24:in `block (3 levels) in <module:Logging>'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activejob-6.0.3.1/lib/active_job/logging.rb:45:in `block in tag_logger'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/tagged_logging.rb:80:in `block in tagged'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/tagged_logging.rb:28:in `tagged'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/tagged_logging.rb:80:in `tagged'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activejob-6.0.3.1/lib/active_job/logging.rb:45:in `tag_logger'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activejob-6.0.3.1/lib/active_job/logging.rb:21:in `block (2 levels) in <module:Logging>'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/callbacks.rb:121:in `instance_exec'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/callbacks.rb:121:in `block in run_callbacks'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/callbacks.rb:139:in `run_callbacks'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activejob-6.0.3.1/lib/active_job/execution.rb:39:in `perform_now'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activejob-6.0.3.1/lib/active_job/execution.rb:18:in `perform_now'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/noticed-1.2.20/lib/noticed/base.rb:105:in `block in run_delivery_method'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/callbacks.rb:101:in `run_callbacks'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/noticed-1.2.20/lib/noticed/base.rb:96:in `run_delivery_method'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/noticed-1.2.20/lib/noticed/base.rb:78:in `run_delivery'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/noticed-1.2.20/lib/noticed/base.rb:47:in `block (2 levels) in deliver'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/noticed-1.2.20/lib/noticed/base.rb:46:in `each'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/noticed-1.2.20/lib/noticed/base.rb:46:in `block in deliver'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/callbacks.rb:101:in `run_callbacks'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/noticed-1.2.20/lib/noticed/base.rb:45:in `deliver'
(pry):3:in `__pry__'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:290:in `eval'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:290:in `evaluate_ruby'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:659:in `handle_line'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:261:in `block (2 levels) in eval'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:260:in `catch'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:260:in `block in eval'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:259:in `catch'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/pry-0.13.1/lib/pry/pry_instance.rb:259:in `eval'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/pry-0.13.1/lib/pry/repl.rb:77:in `block in repl'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/pry-0.13.1/lib/pry/repl.rb:67:in `loop'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/pry-0.13.1/lib/pry/repl.rb:67:in `repl'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/pry-0.13.1/lib/pry/repl.rb:38:in `block in start'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/pry-0.13.1/lib/pry/input_lock.rb:61:in `__with_ownership'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/pry-0.13.1/lib/pry/input_lock.rb:78:in `with_ownership'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/pry-0.13.1/lib/pry/repl.rb:38:in `start'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/pry-0.13.1/lib/pry/repl.rb:15:in `start'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/pry-0.13.1/lib/pry/pry_class.rb:191:in `start'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-6.0.3.1/lib/rails/commands/console/console_command.rb:70:in `start'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-6.0.3.1/lib/rails/commands/console/console_command.rb:19:in `start'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-6.0.3.1/lib/rails/commands/console/console_command.rb:102:in `perform'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/thor-1.0.1/lib/thor/command.rb:27:in `run'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/thor-1.0.1/lib/thor/invocation.rb:127:in `invoke_command'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/thor-1.0.1/lib/thor.rb:392:in `dispatch'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-6.0.3.1/lib/rails/command/base.rb:69:in `perform'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-6.0.3.1/lib/rails/command.rb:46:in `invoke'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-6.0.3.1/lib/rails/commands.rb:18:in `<main>'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/dependencies.rb:324:in `block in require'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/dependencies.rb:291:in `load_dependency'
/home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.3.1/lib/active_support/dependencies.rb:324:in `require'
bin/rails:9:in `<main>'
ActiveRecord::RecordInvalid: Validation failed: Account must exist
from /home/ryanchin/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activerecord-6.0.3.1/lib/active_record/validations.rb:80:in `raise_validation_error'
Ryan Chin
Ended up fixing it by adding:
format: :to_database

and def to_database

class NewFan < Noticed::Base
  deliver_by :database, format: :to_database
  deliver_by :action_cable, format: :to_websocket

  # Add required params
  #
  param :fan, :account

  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
Notifications
You’re not receiving notifications from this thread.