It seems that when I run my application in production mode I am getting the following inside my console:
/home/Desktop/Portal/app/mailers/holiday_mailer.rb:2:in
`<class:HolidayMailer>': uninitialized constant HolidayMailer::DEFAULT_FROM (NameError)
I have looked at the following SO question Rails 3 Action Mailer uninitialized constant. It appears that I have not made that mistake as my set up is as followed:
environment.rb
require File.expand_path('../application', __FILE__)
# Initialize the rails application
Portal::Application.initialize!
ActionMailer::Base.delivery_method = :smtp
DEFAULT_FROM = "portal@gmail.com"
holiday mailer
class HolidayMailer < ActionMailer::Base
default :from => DEFAULT_FROM
def holiday_confirmation(holiday)
@holiday = holiday
mail(:to => holiday.user.email, :subject => "Your Absence Request")
end
end
Holiday Controller
def update()
admin = User.find(current_user.role? :administrator)
holiday = Holiday.find(params[:id])
user = User.find(id = holiday.user_id)
if holiday.update_attributes(params[:holiday])
if holiday.state == "approved"
user.absentdays = user.absentdays - (holiday.days_used).to_i
user.save
end
redirect_to absence_path, :notice => "request updated!"
#email the user to tell them the state of their holiday
HolidayMailer.holiday_confirmation(holiday).deliver
else
render 'edit'
end
end
It seems though this is wrong
I don’t know why it is throwing an error in the production, but I can tell you how to fix this problem.
I replicated this scenario in my rails 3.2.11 app and I got the same error in production. There are two possible fixes.
Make an initializer file for mail settings (config/initializers/mail_settings.rb) and put this variable DEFAULT_FROM in that file.
The second approach is neat, because its a configuration for mailer and the variable will be available in both development and production environments. Both these approaches would require you to restart your dev/deployment server.
Hope this helps.