Re: Actionmailer Help Needed

Kendall Gifford
Thu, 28 Jul 2011 22:33:14 -0000

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.rb
>
> class TaskMailer < ActionMailer::Base
>   def task_due(task)
>       recipients @task.user.email
>       from       "em...-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org"
>       subject    "Your report entitled"
>       sent_on    Time.now
>       content_type "text/html"
>       body       :task => task
>   end
> end
>
> In 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
> end
>
> And in my view, task_due.html.erb, I''ve tried this.
>
>
>
>
>     <meta content="text/html; charset=UTF-8"
http-equiv="Content-Type"
> />
>
>
> Ahoy! <%= @task.responsible %>
>     <% 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.


>
>
> This results in a loop, stack level too deep. I think I understand why.
>
Yeah, you''ve got a recursion loop.

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
>
>
> Do you really want 1 email per matching task? Or do you want one email per
user who has at least one matching task? Part of your code is written as if
you want the former while part of it is written as if you want the latter.

--
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