Skip to content

Instantly share code, notes, and snippets.

@timmatheson
Created February 9, 2010 01:39
Show Gist options
  • Save timmatheson/298819 to your computer and use it in GitHub Desktop.
Save timmatheson/298819 to your computer and use it in GitHub Desktop.
## app/controllers/users_controller.rb
class UsersController < ApplicationController::Base
def create
@user = User.new(params[:user])
if @user.save
SomeMailer.deliver_activation_email(@user, self) # pass in the controller object
redirect_to some_path
end
end
end
## app/models/some_mailer.rb
class SomeMailer < ActionMailer::Base
def activation_email(user, controller)
from "blah@#{detect_host(controller)}"
recipients user.email
body :user => user
content_type "text/html"
end
private
# from the controller object
def detect_host(controller)
@current_host ||= "#{controller.request.host}:#{controller.request.port}"
end
end
## app/views/some_mailer/activation_email.html.erb
Activate: <%= link_to "Activate", activate_user_url(@user) %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment