似乎当我在生产模式下运行我的应用程序时,我在控制台中得到以下信息:
/home/Desktop/Portal/app/mailers/holiday_mailer.rb:2:in
`<class:HolidayMailer>': uninitialized constant HolidayMailer::DEFAULT_FROM (NameError)
我查看了以下 SO 问题Rails 3 Action Mailer uninitialized constant。看来我没有犯这个错误,因为我的设置如下:
环境.rb
require File.expand_path('../application', __FILE__)
# Initialize the rails application
Portal::Application.initialize!
ActionMailer::Base.delivery_method = :smtp
DEFAULT_FROM = "portal@gmail.com"
假日邮递员
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
假日控制器
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
似乎这是错误的