I want to send exception mail to email_ids stored in yb_notifier_email_ids table. Previously, email_id was hardcoded in production.rb file. I want to send mail by using model. But as configurations file are loaded before active_records I am not able to do this.
-----------migration
class CreateYbNotifierEmailIds < ActiveRecord::Migration
def change
create_table :yb_notifier_email_ids do |t|
t.string :email_id
t.timestamps null: false
end
end
end
----------------------------required------------
config.middleware.use ExceptionNotification::Rack,
:email => {
:email_prefix => "[YB] ",
:sender_address => %{"YB Notifier" <noreply@yb.com>},
:exception_recipients => YbNotifierEmailIds.pluck(:email_id)
}
end
-----------------------I have tried this:
Rails.application.middleware.use ExceptionNotification::Rack,
:email => {
:email_prefix => "[YB-QA] ",
:sender_address => %{"YB Notifier" <noreply@yb.com>},
:exception_recipients => defined?(YbNotifierEmailId) && YbNotifierEmailId.table_exists? ? YbNotifierEmailIds.pluck(:email_id) : %w{test@ssolution.com}
}
but defined?(YbNotifierEmailId) && YbNotifierEmailId.table_exists?
this condition is getting failed.
This is resolved using lambda. lambda {TableName.pluck(:email_id)}. Thanks