addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1linklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahoo

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

From: Billy
Sent on: Friday, June 22, 2007 1:52 PM
I used one solution for a while, where inside of my environment files, I did something like:

config.app_config.email_link_hostname = 'www.tobi.com'

Then I could access it anywhere by doing:

AppConfig.email_link_hostname

It worked but it was dirty. Another guy over here worked some plugin magic so that any model could use url_for/link_to ... then it was just a matter of setting the following:

default_url_options[:host] = AppConfig.email_link_hostname

url_for would then automatically use that as the hostname. If you had different hostnames for your different environments, you just put the appropriate AppConfig.email_link_hostname in that environmentname.rb file.

On 6/22/07, Brandon Keene <[address removed]> wrote:
This is why I don't like the controller based solutions.  They totally kill anything that isn't within the server context.

Since a lot of jobs are done in the background another solution is needed.  Ryan's solution to just pass it a URL could work for this case.  You could store the base url with the object that will be operated on later.  For example, store the base url inside a User record and then pass that to UserNotifier.  Still less than ideal but it gets the job done.


On 6/22/07, Billy <[address removed]> wrote:
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





--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ( [address removed])
This message was sent by Billy ([address removed]) from The East Bay Ruby Meetup Group.
To learn more about Billy, 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

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