Link_to and url_for in ActionMailer

I am new to ActionMailer and having a problem.

I want to be able to send a notification e-mail when a new item is added
to a list. Sending an e-mail to the right people on creation is working
fine.

However, I want to include in the e-mail a link to the application so
that users can click on the link in the e-mail and immediately be taken
to the show view for the new item. When I add a link_to element to the
e-mail template, I get the error message:

undefined method `url_for’ for #JobRequestMailer:0x77fe458

I have tried adding a link to the application helper to the mailer
model:

helper :application

but that doesn’t seem to have helped.

Can some one either tell me how to access an ActionView method from
within an ActionMailer object, or provide another work around.

I know I could construct the anchor manually, but then I’ll need to
rewrite it if the application moves.

El 28/11/2006, a las 14:59, Rob N.
escribió:

that users can click on the link in the e-mail and immediately be

but that doesn’t seem to have helped.

Can some one either tell me how to access an ActionView method from
within an ActionMailer object, or provide another work around.

I know I could construct the anchor manually, but then I’ll need to
rewrite it if the application moves.

That is exactly the point. link_to and url_for construct the url by
knowing the hostname of the request. ActionMailer can’t know this
unless you pass the url. You may want to build the url in the
controller and pass the url to the deliver function.

If you are calling the mailer from a cron job you will have to put a
fixed hostname, since it can’t guess it with no request object.


Posted via http://www.ruby-forum.com/.


Jorge B. Ordovás [email protected]
http://amedias.org/ [ES]
http://koke.amedias.org/ [EN]

Warp Networks http://www.warp.es/
María de Luna 11, 50018 Zaragoza,
España