The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
What's New in Edge Rails: Build URLs in Your ActionMailers (and other non-controllers)

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
rwdaigle

Posts: 312
Nickname: rwdaigle
Registered: Feb, 2003

Ryan is a passionate ruby developer with a strong Java background.
What's New in Edge Rails: Build URLs in Your ActionMailers (and other non-controllers) Posted: Aug 24, 2006 6:17 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by rwdaigle.
Original Post: What's New in Edge Rails: Build URLs in Your ActionMailers (and other non-controllers)
Feed Title: Ryan's Scraps
Feed URL: http://feeds.feedburner.com/RyansScraps
Feed Description: Ryan Daigle's various technically inclined rants along w/ the "What's new in Edge Rails" series.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by rwdaigle
Latest Posts From Ryan's Scraps

Advertisement

For a long time there was no way to generate a URL within an ActionMailer. If you wanted to send a registration email when a user signs up for your application you would have had to pass in the url to be included in the email:


class MyController < ApplicationController
  def register
    # .. registration logic ...
    UserMailer.deliver_registration(user, home_url)
  end
end

class UserMailer < ActionMailer::Base
  def registration(user, url)
    @body = { 'user' => user, 'home' => url }
  end
end

This is hardly a hack, but it’s not as nice as it could be. It would be nice if the mailer itself could generate the url – or perhaps if the email template itself could generate the url? That day has come with the new ActionController::UrlWriter module.

Just include ActionController::UrlWriter in your mailer and you get access to all the familiar url_for and even the named url methods (home_url in this example):


class UserMailer < ActionMailer::Base
  include ActionController::UrlWriter
  def registration(user)
    @body = { 'user' => user, 'home' => home_url }
  end
end

tags: , ,

Read: What's New in Edge Rails: Build URLs in Your ActionMailers (and other non-controllers)

Topic: Extending the wmii WM with more plugins; thanks, Nathan Previous Topic   Next Topic Topic: Personality Traits of the Best Software Developers

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use