我似乎無法使我的行動起來無論何時寶石工作。我正試圖在開發中運行應用程序,其中電子郵件將在特定時間發送給特定個人。每當寶石每日電子郵件使用actionmailer不發送
在我schedule.rb文件我有以下幾點:
every :day, :at => '12:48pm' do
runner "FoodPlan.food_email"
end
在我的控制器稱爲food_plans_controller.rb我:
def self.food_email
@food_plans = FoodPlan.where(food_plan_date: Date.today).order('meal ASC')
UserMailer.food_email(@food_plans).deliver_now
end
在user_mailer.rb我有(請注意我刪除電子郵件爲隱私的原因):
def food_email (food)
@food_plans = food
mail(to: '[email protected]', subject: 'Food Orders for #{Date.today}')
end
我有一個名爲user_mailer的視圖中的文件夾,裏面是一個叫做food_email.html.erb與FF文件:
<!DOCTYPE html>
<html>
</head>
<body>
<h1>title</h1>
<p>
Good morning, -----!
<br><br>
Meal Plans for <%=Date.today%>:
<br><br>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>#</th>
<th>Meal Plan</th>
<th>Ordered by</th>
<th>Room Number</th>
<th>Received by</th>
<th>Signature</th>
</tr>
</thead>
<tbody>
<%countint=1%>
<% @food_plans.each do |food_plan| %>
<tr>
<td><%=countint%></td>
<td><%= food_plan.meal %></td>
<td><%=food_plan.applicant.first_name%>
<%=food_plan.applicant.last_name%></td>
<td><%=food_plan.applicant.room_number%></td>
<%countint+=1%>
<td></td>
<td></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<br>
---.
<br>
<br>
If you have any concerns, don't hesitate to call us at ------.
<br>
<br>
Thanks, <br>----
</p>
</body>
</html>
在我的開發配置我已(我刪除的電子郵件和密碼):
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'example.com',
user_name: '-------',
password: '-------',
authentication: 'plain',
enable_starttls_auto: true }
我曾嘗試閱讀本guide但我仍然無法讓寶石與actionmailer一起工作。我也閱讀了每當寶石documentation,但我仍然無法弄清楚我做錯了什麼。 :(
我沒有得到任何錯誤,它只是郵件沒有發送。
具體什麼不行,你有什麼問題?你有錯誤嗎?郵件是否被髮送,即使你期望它? –
電子郵件未被髮送。我不認爲它甚至會進入調度程序。我正在查看本地主機終端的日誌,即使在調度程序中指定的時間內,日誌也沒有任何更改。 – Acrux