Hi all, I''m trying to create a worker to send a mail to all the users in my db. Right now I''m doing the tests, this is the code in my worker (Masivo is the ActionMailer subclass): def do_work(args) @progress = 0 @logger.info("MAILER: starting job") records = Record.find(:all) total = records.size records.each_with_index do |record, idx| recipients = record.emails.to_a email = Masivo.create_mail_prueba(recipients) email.set_content_type("text/html") Masivo.deliver(email) sleep(10) # this is here for testing purposes end @logger.info("MAILER: job done") @progress = 100 end this is the code in Masivo: def mail_prueba(recipients) @recipients = recipients @from = "myself at mydomain.com" @subject = "test email" @sent_on = Time.now @body = {} end If I do this, I get an exception: No rhtml, rxml, rjs or delegate template found for mail_prueba - (ActionView::ActionViewError) I had to put a render :file at the end of the mail_prueba function, and even that way the email is not sent... Any ideas on what could be the problem? btw... this is the code in the controller that creates the worker: def email_prueba MiddleMan.new_worker(:class => :mailer_worker, :args => "", :job_key => :emailer) redirect_to(:action => ''email_prueba_progress'') end def email_prueba_progress render(:text => "Progreso: #{MiddleMan[:emailer].progress}") end thanks for any hint. -- rolando -- [[ knowledge is empty, fill it ]] -- "Tam pro papa quam pro rege bibunt omnes sine lege."
Hi all, I''m trying to create a worker to send a mail to all the users in my db. Right now I''m doing the tests, this is the code in my worker (Masivo is the ActionMailer subclass): def do_work(args) @progress = 0 @logger.info("MAILER: starting job") records = Record.find(:all) total = records.size records.each_with_index do |record, idx| recipients = record.emails.to_a email = Masivo.create_mail_prueba(recipients) email.set_content_type("text/html") Masivo.deliver(email) sleep(10) # this is here for testing purposes end @logger.info("MAILER: job done") @progress = 100 end this is the code in Masivo: def mail_prueba(recipients) @recipients = recipients @from = "myself at mydomain.com" @subject = "test email" @sent_on = Time.now @body = {} end If I do this, I get an exception: No rhtml, rxml, rjs or delegate template found for mail_prueba - (ActionView::ActionViewError) I had to put a render :file at the end of the mail_prueba function, and even that way the email is not sent... Any ideas on what could be the problem? btw... this is the code in the controller that creates the worker: def email_prueba MiddleMan.new_worker(:class => :mailer_worker, :args => "", :job_key => :emailer) redirect_to(:action => ''email_prueba_progress'') end def email_prueba_progress render(:text => "Progreso: #{MiddleMan[:emailer].progress}") end thanks for any hint. -- rolando -- [[ knowledge is empty, fill it ]] -- "Tam pro papa quam pro rege bibunt omnes sine lege."
Your workers reside in lib/workers, which means the path for them back to RAILS_ROOT is back two levels, and thus the mail templates are back two as well: File.expand_path(File.dirname(__FILE__) + "../../../file.txt")) see: http://rubyforge.org/pipermail/backgroundrb-devel/2006-August/000163.html posted just a few days ago.... -- Charles Brian Quinn self-promotion: www.seebq.com highgroove studios: www.highgroove.com slingshot hosting: www.slingshothosting.com On 8/7/06, Rolando Abarca <funkaster at gmail.com> wrote:> Hi all, > I''m trying to create a worker to send a mail to all the users in my > db. Right now I''m doing the tests, this is the code in my worker > (Masivo is the ActionMailer subclass): > > def do_work(args) > @progress = 0 > @logger.info("MAILER: starting job") > records = Record.find(:all) > total = records.size > records.each_with_index do |record, idx| > recipients = record.emails.to_a > email = Masivo.create_mail_prueba(recipients) > email.set_content_type("text/html") > Masivo.deliver(email) > sleep(10) # this is here for testing purposes > end > @logger.info("MAILER: job done") > @progress = 100 > end > > this is the code in Masivo: > > def mail_prueba(recipients) > @recipients = recipients > @from = "myself at mydomain.com" > @subject = "test email" > @sent_on = Time.now > @body = {} > end > > If I do this, I get an exception: > > No rhtml, rxml, rjs or delegate template found for mail_prueba - > (ActionView::ActionViewError) > > I had to put a render :file at the end of the mail_prueba function, > and even that way the email is not sent... Any ideas on what could be > the problem? > > btw... this is the code in the controller that creates the worker: > > def email_prueba > MiddleMan.new_worker(:class => :mailer_worker, :args => "", > :job_key => :emailer) > redirect_to(:action => ''email_prueba_progress'') > end > > def email_prueba_progress > render(:text => "Progreso: #{MiddleMan[:emailer].progress}") > end > > thanks for any hint. > -- > rolando -- [[ knowledge is empty, fill it ]] -- > "Tam pro papa quam pro rege bibunt omnes sine lege." > _______________________________________________ > Backgroundrb-devel mailing list > Backgroundrb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/backgroundrb-devel >
On 8/7/06, Charles Brian Quinn <me at seebq.com> wrote:> Your workers reside in lib/workers, which means the path for them back > to RAILS_ROOT is back two levels, and thus the mail templates are back > two as well: > > File.expand_path(File.dirname(__FILE__) + "../../../file.txt")) > > see: http://rubyforge.org/pipermail/backgroundrb-devel/2006-August/000163.html > > posted just a few days ago.... > -- > Charles Brian QuinnCharles, I read the referenced post a couple of days ago, and I still don''t understand it. Are you saying that we need to use render :file and your File.expand line? I guess I didn''t understand how you actually use it to get the email sent (sorry, I can be a bit dense sometimes). Cheers, Brett
If you are only using this mailer for mail sent from a worker, you can use in your main mail initializing block (your sent method): @subject = blah @recipients = blah @body = blah @template = "../../path/to/template" # instead of ./path/to/template http://railsmanual.com/class/ActionMailer::Base On 8/7/06, Brett Walker <lapomme00 at gmail.com> wrote:> On 8/7/06, Charles Brian Quinn <me at seebq.com> wrote: > > Your workers reside in lib/workers, which means the path for them back > > to RAILS_ROOT is back two levels, and thus the mail templates are back > > two as well: > > > > File.expand_path(File.dirname(__FILE__) + "../../../file.txt")) > > > > see: http://rubyforge.org/pipermail/backgroundrb-devel/2006-August/000163.html > > > > posted just a few days ago.... > > -- > > Charles Brian Quinn > > Charles, I read the referenced post a couple of days ago, and I still > don''t understand it. Are you saying that we need to use render :file > and your File.expand line? I guess I didn''t understand how you > actually use it to get the email sent (sorry, I can be a bit dense > sometimes). > > Cheers, > Brett > _______________________________________________ > Backgroundrb-devel mailing list > Backgroundrb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/backgroundrb-devel >-- Charles Brian Quinn self-promotion: www.seebq.com highgroove studios: www.highgroove.com slingshot hosting: www.slingshothosting.com
On 8/7/06, Charles Brian Quinn <me at seebq.com> wrote:> If you are only using this mailer for mail sent from a worker, you can > use in your main mail initializing block (your sent method): > > @subject = blah > @recipients = blah > @body = blah > @template = "../../path/to/template" # instead of ./path/to/templateOk, I got the idea (I think), but it still not working. My mail views are in the default directory (app/views/masivo/) So I set @template to this: @template = "../../app/views/masivo/mail_prueba" (and i''ve restarted the rails app and the backgroundrb server) is this the way it should be? I''m a bit confused... :-S -- rolando -- [[ knowledge is empty, fill it ]] -- "Tam pro papa quam pro rege bibunt omnes sine lege."
On 8/7/06, Charles Brian Quinn <me at seebq.com> wrote:> what about changing template_root -- it''s an actionmailer > configuration variable.yes... that''s the first thing I tried. Didn''t work either... :-( -- rolando -- [[ knowledge is empty, fill it ]] -- "Tam pro papa quam pro rege bibunt omnes sine lege."
try: in your worker require File.dirname(__FILE__) + "../../../config/environment.rb" ActionMailer::Base.template_root File.expand_path(File.dirname(__FILE__) + "../../../app/views") NotificationMailer.deliver_daily_report(users, rep, items) the first line will load environment.rb and rails, initializing your mail transport second line defines the template root, since we are in a different working dir than AM expected third line... you should see it... that works for me 2006/8/7, Rolando Abarca <funkaster at gmail.com>:> > On 8/7/06, Charles Brian Quinn <me at seebq.com> wrote: > > what about changing template_root -- it''s an actionmailer > > configuration variable. > > yes... that''s the first thing I tried. Didn''t work either... :-( > > -- > rolando -- [[ knowledge is empty, fill it ]] -- > "Tam pro papa quam pro rege bibunt omnes sine lege." > _______________________________________________ > Backgroundrb-devel mailing list > Backgroundrb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/backgroundrb-devel >-- Michael Siebert <info at siebert-wd.de> www.stellar-legends.de - Weltraum-Browsergame im Alpha-Stadium -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20060807/d064d835/attachment.html
On 8/7/06, Michael Siebert <info at siebert-wd.de> wrote:> try: > in your worker > require File.dirname(__FILE__) + > "../../../config/environment.rb" > ActionMailer::Base.template_root > File.expand_path(File.dirname(__FILE__) + "../../../app/views") > NotificationMailer.deliver_daily_report(users, rep, > items)thanks!! that worked... although not exactly like that, this worked: require File.dirname(__FILE__) + "/../../config/environment.rb" ActionMailer::Base.template_root File.expand_path(File.dirname(__FILE__) + "/../../app/views") Had to add a slash before and only go back two directories... -- rolando -- [[ knowledge is empty, fill it ]] -- "Tam pro papa quam pro rege bibunt omnes sine lege."
hrm... exactly the code i posted works for me... huh? 2006/8/7, Rolando Abarca <funkaster at gmail.com>:> > On 8/7/06, Michael Siebert <info at siebert-wd.de> wrote: > > try: > > in your worker > > require File.dirname(__FILE__) + > > "../../../config/environment.rb" > > ActionMailer::Base.template_root > > File.expand_path(File.dirname(__FILE__) + "../../../app/views") > > NotificationMailer.deliver_daily_report(users, rep, > > items) > > thanks!! that worked... although not exactly like that, this worked: > > require File.dirname(__FILE__) + "/../../config/environment.rb" > ActionMailer::Base.template_root > File.expand_path(File.dirname(__FILE__) + "/../../app/views") > > Had to add a slash before and only go back two directories... > -- > rolando -- [[ knowledge is empty, fill it ]] -- > "Tam pro papa quam pro rege bibunt omnes sine lege." > _______________________________________________ > Backgroundrb-devel mailing list > Backgroundrb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/backgroundrb-devel >-- Michael Siebert <info at siebert-wd.de> www.stellar-legends.de - Weltraum-Browsergame im Alpha-Stadium -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20060807/ed59dc24/attachment-0001.html