Re: [ruby-81] Dynamic hostname in ActionMailer views?

From: Billy
Sent on: Friday, June 22, 2007 12:21 PM
That method works OK until you don't have a controller (like when sending out mass emails or using script/runner to send mail). I havent figured out a clean way of making that work yet :(

On 6/21/07, Brandon Keene <[address removed]> wrote:
Thanks Guy,
I successfully implemented it using this approach as well. 

As you said, something cleaner / conventional welcome.

Regards,
Brandon


On 6/21/07, Guy Argo <[address removed]> wrote:
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 => user.activation_key )
  end
...
end

and then in the controller you just need to pass self:

...
            UserNotifier.deliver_activation ( self, @user )
            render( :action => 'activation_delivered' )
...

Cleaner suggestions welcome...

On Jun 21, 2007, at 1:49 PM, Brandon Keene wrote:

Hey guys,
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 ( http://staging.example.com)
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.

Any thoughts?

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.

Thanks!
Brandon




--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ( [address removed])
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, click here

Meetup.com Customer Service: [address removed]
632 Broadway New York NY 10012 USA





--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ( [address removed])
This message was sent by Guy Argo ([address removed]) from The East Bay Ruby Meetup Group.
To learn more about Guy Argo, visit his/her member profile
To unsubscribe or to update your mailing list settings, click here

Meetup.com Customer Service: [address removed]
632 Broadway New York NY 10012 USA





--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ( [address removed])
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, click here

Meetup.com Customer Service: [address removed]
632 Broadway New York NY 10012 USA

Our Sponsors

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy