I had this exact same problem and I ended up
passing in the controller to the ActionMailer-derived model:
class UserNotifier < ActionMailer::Base
def activation( controller, user )
setup_email( user.email, user )
@subject += 'Please activate your new account'
@body[:url] = controller.url_for( :controller => 'login', :action => 'activation', :id =>
and then in the controller you just need to pass self:
( self, @user )
render( :action => 'activation_delivered' )
Cleaner suggestions welcome...
On Jun 21, 2007, at 1:49 PM, Brandon Keene wrote:
This one has me stumped and yes it does violate the basic idea of MVC just a bit, but I think it's a real world problem.
Ok so I have three environments on three different machines.
1. Production ( http://example.com)
2. Staging (
3. Development (localhost)
I need to send an account activation message when a person signs up.
A clean way to manage this would be to place this logic inside the Person model and upon create, include a callback to send the email using ActionMailer.
The problem arises because since there's no ActionController in the mix, the view for the ActionMailer message doesn't know its hostname and this can't generate the activation link.
The ActionMailer examples in the pragmatic book hard code the URLs thus avoiding explaining how to get this working in separate locations.
One route is to explicitly invoke the delivery call from an ActionController, say SignupController#signup would call Person.deliver_activation_email(current_hostname). This doesn't feel right.
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list (
This message was sent by Brandon Keene ([address removed]) from The East Bay Ruby Meetup Group.
To learn more about Brandon Keene, visit his/her member profile
To unsubscribe or to update your mailing list settings,
Meetup.com Customer Service: [address removed]
632 Broadway New York NY 10012 USA
This message was sent by Guy Argo ([address removed]) from The East Bay Ruby Meetup Group.