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...@example.com"
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.
<!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 %>
</body>
This results in a loop, stack level too deep. I think I understand why.
Can you help me understand how I display all my records from the found
set?
All the best
Jenny Bx
--
Posted via http://www.ruby-forum.com/.
</body>
This results in a loop, stack level too deep. I think I understand why.
Can you help me understand how I display all my records from the found
set?All the best
Jenny Bx
Thanks for your reply. Am really baffled by this problem - not sure why
I can't get my head around it!!
I'm trying to send one email per user with a list of that user's task
which are due.
The problem is that I've been following tutorials which don't exactly
cover what I'm trying to achieve and am having issues modifying my code
accordingly.
Thanks for your help, looking forward to your reply
Jenny x
Thanks for your answer.
I'm just getting in a pickle with Actionmailer I have to say :(
Am just trying to send a single email to each user. I need the content
to list their due tasks.
That's why I was trying to display the found set.
Thanks, Jx
We created some controller actions to list all tasks, due and overdue as
below:
In our tasks controller:
List current user's due tasks:
@my_due = Task.find(:all, :conditions => ["dueddate <= ? AND user_id = ?
AND status = ?", Date.today + 7.days, current_user.id, false], :include
=> :taskcategories, :order => "dueddate asc")
I actually can't figure out how to list all the users with overdue
tasks.
(We're using devise for authentication, hence the current_user bit)
Is that what you mean?
Sorry for the newbie questions...
Jenny
@task = Task.all
@user = User.find(:all, :conditions => ["@task.dueddate <= ? AND
@task.status = ?", Date.today + 7.days, false])
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Please consider the environment before printing this email.
Regards,
Ok, so I have created the find user action in my controller:
@user = User.joins(:tasks).where("tasks.dueddate <= ? AND tasks.status =
?", Date.today + 7.days, false)
Which works although I need to get the distinct values out now.
What's the next stage to get actionmailer working with this or am I
miles off?
Thanks
Jenny
This is the part that I really don't understand how to deal with. I
don't understand how I link what you've asked me to do above listing the
users with due tasks with actionmailer.
Thanks
Have figured out how to get actionmailer to email those users with tasks
due. That was ok after I got my head around it.
I can get the email view to list ALL tasks but not just those owned by a
user. In my view, I've tried this:
<% Task.tasksdue.find_each do |task| %>
<li> <%= task.title %> </li>
<% end %>
Which calls a scope from my Task model.
scope :tasksdue, lambda {
where("dueddate >= ? AND user_id = ? AND status = ?", Date.today,
:user_id, false)
}
But I don't get any data out of that. If I get rid of the user_id
aspect, it lists all tasks.
How can I adjust that so it works?
Thanks
Jx