I can't seem to make the whenever gem work with my actionmailer. I am trying to run the application in development wherein an email would be sent to a specific individual at a specific time.
In my schedule.rb file I have the following:
every :day, :at => '12:48pm' do
runner "FoodPlan.food_email"
end
In my controller called food_plans_controller.rb I have:
def self.food_email
@food_plans = FoodPlan.where(food_plan_date: Date.today).order('meal ASC')
UserMailer.food_email(@food_plans).deliver_now
end
In user_mailer.rb I have (take note I removed the email for privacy reasons) :
def food_email (food)
@food_plans = food
mail(to: '---------@yahoo.com', subject: 'Food Orders for #{Date.today}')
end
I have a folder in the views called user_mailer, inside it is a file called food_email.html.erb with the 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>
In my development config I have (I removed the email and password):
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'example.com',
user_name: '-------',
password: '-------',
authentication: 'plain',
enable_starttls_auto: true }
I have tried reading this guide but I cannot still get the gem to work with actionmailer. I have also read up on the documentation of the whenever gem but I still can't figure out what I'm doing wrong. :(
I'm not getting any errors, it's just that the email is not sending.