我在生产heroku环境中使用动作邮件程序。当我像这样运行控制台时:
heroku run console
FamilyMailer.notify_family_member(FamilyMember.last)
完美无缺,并发送电子邮件。但是,当我在控制器中编写EXACT SAME行时,它似乎没有激活邮件程序。邮件程序中的puts
语句甚至不会出现在控制台中。这是控制器动作:
def create
puts "in the create action"
@event = Event.find(params[:event_id])
@event.notify_family_members #from Event model called below
end
以下是事件模型:
class Event < ActiveRecord::Base
def notify_family_members
puts "in model method"
FamilyMailer.notify_family_member(FamilyMember.last)
end
end
这是邮件:
class FamilyMailer < ApplicationMailer
default from: "Gold<contact@goldyo.me>"
def notify_family_member(family_member)
puts "in the mailer"
mail(to: family_member.email, subject: "Photos").deliver
end
end
以下是服务器日志:
2016-04-26T20:00:07.110616+00:00 app[web.1]: Started POST "/api/events" for 69.46.236.36 at 2016-04-26 20:00:07 +0000
2016-04-26T20:00:07.231857+00:00 app[web.1]: Processing by Api::EventsController#create as HTML
2016-04-26T20:00:07.231967+00:00 app[web.1]: Parameters: {"event_id"=>7, "event_attendees"=>{"1"=>"Larry Ellison"}, "event"=>{}}
2016-04-26T20:00:07.242261+00:00 app[web.1]: in the create action
2016-04-26T20:00:07.444983+00:00 app[web.1]: in model method
2016-04-26T20:00:07.462242+00:00 app[web.1]: [active_model_serializers] Rendered ActiveModel::Serializer::Null with Event (0.81ms)
2016-04-26T20:00:07.463231+00:00 app[web.1]: Completed 200 OK in 231ms (Views: 9.4ms | ActiveRecord: 26.9ms)
2016-04-26T20:00:07.462845+00:00 heroku[router]: at=info method=POST path="/api/events" host=goldenowl.herokuapp.com request_id=d6aeb940-a65a-4667-be1c-263bee9ef899 fwd="69.46.236.36" dyno=web.1 connect=0ms service=359ms status=200 bytes=824
正如您所看到的,正在调用模型方法,但邮件被忽略。我也尝试将.deliver
更改为.deliver_now
,但这没有用。
我该如何解决这个问题?
答案 0 :(得分:0)
应该在Mailer方法中调用{
"kind": "webfonts#webfontList",
"items": [
[...]
{
"kind": "webfonts#webfont",
"family": "Anonymous Pro",
"variants": [
"regular",
"italic",
"700",
"700italic"
],
"subsets": [
"greek",
"greek-ext",
"cyrillic-ext",
"latin-ext",
"latin",
"cyrillic"
],
"version": "v3",
"lastModified": "2012-07-25",
"files": {
"regular": "http://themes.googleusercontent.com/static/fonts/anonymouspro/v3/Zhfjj_gat3waL4JSju74E-V_5zh5b-_HiooIRUBwn1A.ttf",
"italic": "http://themes.googleusercontent.com/static/fonts/anonymouspro/v3/q0u6LFHwttnT_69euiDbWKwIsuKDCXG0NQm7BvAgx-c.ttf",
"700": "http://themes.googleusercontent.com/static/fonts/anonymouspro/v3/WDf5lZYgdmmKhO8E1AQud--Cz_5MeePnXDAcLNWyBME.ttf",
"700italic": "http://themes.googleusercontent.com/static/fonts/anonymouspro/v3/_fVr_XGln-cetWSUc-JpfA1LL9bfs7wyIp6F8OC9RxA.ttf"
}
},
{
"kind": "webfonts#webfont",
"family": "Antic",
"variants": [
"regular"
],
"subsets": [
"latin"
],
"version": "v4",
"lastModified": "2012-07-25",
"files": {
"regular": "http://themes.googleusercontent.com/static/fonts/antic/v4/hEa8XCNM7tXGzD0Uk0AipA.ttf"
}
},
[...]
]
}
方法。但是,不要使用deliver
,而是使用deliver
或deliver_now
。
将您的控制器更改为:
deliver_later
你的邮件:
def create
FamilyMailer.notify_family_member(FamilyMember.last).deliver_now
end