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
to a list. Sending an e-mail to the right people on creation is
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
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
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.