NoMethodError: undefined method `updated_settings' for #<ActionMailer::Parameterized::Mailer:0x00005635bdaaa9d0> - ruby-on-rails

I am trying to send an email while using noticed gem version 1.4.1
This is my notification class
class Freelancer::UpdatePayoutSetting < Noticed::Base
# Add your delivery methods
deliver_by :database
deliver_by :email, mailer: "FreelancerMailer", method: 'updated_settings'
# deliver_by :slack
# deliver_by :custom, class: "MyDeliveryMethod"
# Add required params
param :user
# Define helper methods to make rendering easier.
def message
t("notifications.client.update_payout_setting.message", name: "#{params[:user]&.first_name} #{params[:user]&.last_name}")
end
def url
freelancer_profile_path
end
end
And this is my Mailer code
class FreelancerMailer < ApplicationMailer
def updated_settings
#user = params[:user]
mail(to: #user.email, subject: "#{#user.name} Your Business Info Update successfully.")
end
end
`
And this is my updated_settings.html.erb code for mailer action
<p>Hi <%= #user.name %>,</p>
<p>Your Payout Setting Update Successfully.</p>
<p>Regards,</p>
<p>Team Loovit</p>
I am calling this by running below command
Freelancer::UpdatePayoutSetting.with(user: current_user).deliver_later(current_user)
And its working fine on my local machine but it produces this Error on my production server
NoMethodError: undefined method `updated_settings' for #ActionMailer::Parameterized::Mailer:0x00005635bdaaa9d0

Related

access "self" from view after sending mail (ruby on rails)

After a user signs up (Devise RegistrationController), I want to send them a welcome email.
Inside my User model, I created a function:
def send_welcome_email
UserMailer.welcome(self).deliver
end
Then I've added after_create :send_welcome_email
Inside the email view, I need to access variables.
<p><span><strong>Hi <%= self.name %>,</strong></span></p>
Returns an error:
undefined method `name' for #<#<Class:0x00007fa7d18e13b0>:0x00007fa7e4025358>
It makes sense that this would result in the error above, but I'm not sure how I can access variables from the model (that was just created).
I was following this asnwer: https://stackoverflow.com/a/17480095/9200273
Welcome method:
def welcome(user)
mail(
to: user.email,
subject: 'Welcome to Site!',
from: "support#site.com"
)
end
You can pass objects to the Mailer class using the with method like this:
UserMailer.with(user: self).welcome.deliver
Inside the UserMailer class:
def welcome_email
#user = params[:user]
...
end
In the view:
<%= #user.name %>
Reference: https://guides.rubyonrails.org/action_mailer_basics.html

Define_method rails mailer

Is it possible to write mailer methods with define_method,because i need almost similar methods,like
notify_user_approved & notify_user_rejected
%w(approved rejected).each do|meth|
define_method("notify_user_#{meth}") do |user,subject|
#url = user.email
#user = user
mail(to: #url, subject: subject)
end
end
Notification is my mailer class name
Notification.notify_user_rejected(User.last,'approved').deliver_now
i having NoMethodError: undefined methodmail' for Notification:Class
when to try run my mailer
whole class
class Notification < ActionMailer::Base
%w(approved rejected).each do|meth|
define_method("notify_user_#{meth}") do |user,subject|
#url = user.email
#user = user
mail(to: #url, subject: subject)
end
end
end

Email 'email_calendar' not found in CalendarMailerPreview Rails Mailer Preview

I've created a basic mailer and am not able to see the preview using the following path: http://localhost:3000/rails/mailers/calendar_mailer/calendar_email
Here is my mailer, preview, and email body code:
calendar_mailer.rb:
class CalendarMailer < ActionMailer::Base
default from: "notifications#cogsmart.com"
def calendar_email(user)
#user = user
mail(to: #user.email, subject: 'Your Cogsmart To Do List')
end
end
calendar_mailer_preview.rb:
class CalendarMailerPreview < ActionMailer::Preview
def calendar_email
CalendarMailer.calendar_email(User.first)
end
end
calendar_email.html.erb:
<h1>Thanks #user.name for using Cogsmart, here's your calendar</h1>
As described here
The preview needs to go in the test/mailers/previews folder

Generating confirmation url in custom devise mailer

I am using the Mandrill API to handle my transactional email for a variety of reasons. One issue I am encountering is generating the confirmation_url, edit_password_url and unlock_url in the new mailer. I am including Devise's URL helpers in the new mailer. Everything else in the email is being generated properly.
I am getting the following error:
NoMethodError (undefined method `main_app' for #<DeviseMailer:0x007f812b6abe78>):
app/mailers/devise_mailer.rb:15:in `confirmation_instructions'
app/controllers/lenders/registrations_controller.rb:9:in `create'
devise_mailer.rb
class DeviseMailer < MandrillMailer::TemplateMailer
helper :application
include Devise::Controllers::UrlHelpers
default from: 'no-reply#test.com'
def confirmation_instructions(record, token)
mandrill_mail template: 'Confirmation Instructions',
subject: 'Confirm Email',
from_name: 'Test',
to: { email: record.email },
vars: {
'FNAME' => record.first_name,
'LIST_COMPANY' => "Apples",
'HTML_LIST_ADDRESS_HTML' => "1 Infinite Loop",
'CONFIRMATION_LINK' => confirmation_url(record, :confirmation_token => token)
}
end
end
Thank you for the help
For anyone hitting this issue - I had the same method missing issue when using mandrill_mailer to replace devise's customer mailer.
Using the above example above I fixed it like so
class DeviseMailer < MandrillMailer::TemplateMaile
# ..... mailer code in here here .....
private
def main_app
Rails.application.routes.default_url_options[:host] = Rails.application.routes.default_url_options[:host]
Rails.application.routes.url_helpers
end
end

undefined method `split' for nil:NilClass when sending mail, on staging

undefined method `split' for nil:NilClass when sending mail, on staging.
NoMethodError: undefined method `split' for nil:NilClass
Has anyone experienced this bug? In the development environment, letters go perfectly
21 File "/var/www/vectoring-staging/releases/20140505020949/app/models/feedback.rb" line 11 in deliver
22 File "/var/www/vectoring-staging/releases/20140505020949/app/controllers/feedbacks_controller.rb" line 4 in "createp/controllers/feedbacks_controller.rb" line 4 in create
class FeedbacksController < ApplicationController
def create
#feedback = Feedback.new(params[:feedback])
#feedback.deliver if #feedback.valid?
end
end
class Feedback
include ActiveModel::Model
attr_accessor :email, :message
attr_writer :subject
validates :message, presence: true, allow_blank: false
validates_format_of :email, with: /\A([^#\s]+)#((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, allow_blank: true
def deliver
FeedbackMailer.new_feedback(self).deliver
end
def subject
#subject = 'A new feedback' if #subject.blank?
#subject
end
end
class FeedbackMailer < ActionMailer::Base
layout 'email'
def new_feedback(feedback)
#message = feedback.message
mail(to: APP_CONFIG.feedback['to_send'], subject: feedback.subject, reply_to: feedback.email)
end
end
Check if the paths to the assets (i.e. CSS) in your email are correct (and exist).

Resources