On Thursday, July 28, 2011 10:05:01 AM UTC-6, Ruby-Forum.com User wrote:
Hello everyone,Nice to meet you all, am new to the forum.
I'm stuck with rake / actionmailer trying to display a set of found
records.We have a simple actionmailer rake task that is supposed to send a daily
email digest of tasks that are due for a specific user. So far, it's
working but the email only displays the first message.In my task model
scope :tasksdue, lambda {
where("dueddate > ? AND status = ?", Date.today, false)
}def self.send_reminders
Task.tasksdue.find_each do |task|
TaskMailer.deliver_task_due task
end
task_mailer.rbclass TaskMailer < ActionMailer::Base
def task_due(task)
recipients @task.user.email
from "em...@example.com"
subject "Your report entitled"
sent_on Time.now
content_type "text/html"
body :task => task
end
endIn my rake tasks file I have
namespace :cron do
desc "Send email reminders to all users"
task :send_reminders => :environment do
Task.send_reminders
end
endAnd in my view, task_due.html.erb, I've tried this.
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type"
/>
</head>
<body>
<h1>Ahoy! <%= @task.responsible %></h1>
<% Task.send_reminders.each do |report| %>
<%= Task.send_reminders.title %>
<% end %>
Yeah, so why are you calling "Task.send_reminders" in your template? I don't think this is what you want.
</body>
This results in a loop, stack level too deep. I think I understand why.
Given you've got at least one Task.tasksdue
When call Task.send_reminders
1. Task.send_reminders calls TaskMailer.deliver_task (passing the task instance)
2. TaskMailer.deliver_task results in the rendering of the task_due.html.erb template
3. The task_due.html.erb template calls TaskMailer.deliver_task (a.k.a., GOTO #1)
Can you help me understand how I display all my records from the found
set?All the best
Jenny Bx
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/Q94ap87jIx4J.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
No comments:
Post a Comment