Skip to content
This repository has been archived by the owner on Aug 15, 2018. It is now read-only.

Commit

Permalink
fixed mailer
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Adams committed Nov 23, 2008
1 parent 5f168b7 commit 1203be9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/controllers/application.rb
Expand Up @@ -3,6 +3,7 @@ class ApplicationController < ActionController::Base
include SiteSettingsHelper

before_filter :login_from_cookie, :setup_plugin_nav, :set_layout_variables, :load_menu
around_filter :inhibit_retardase

helper :all, :testimonials, :site_settings

Expand Down
3 changes: 3 additions & 0 deletions config/initializers/dependencies.rb
Expand Up @@ -5,3 +5,6 @@

# fix multiple submit buttons in ajax calls
require 'tufty/button_disambiguation'

# make actionmailer nicer to deal with, w/r/t url creation
require 'url_writer_retardase_inhibitor'
43 changes: 43 additions & 0 deletions lib/url_writer_retardase_inhibitor.rb
@@ -0,0 +1,43 @@
module UrlWriterRetardaseInhibitor
module ActionController
def self.included(ac)
ac.send(:include, InstanceMethods)
end

module InstanceMethods
def inhibit_retardase
begin
request = self.request
::ActionController::UrlWriter.module_eval do
@old_default_url_options = default_url_options.clone
default_url_options[:host] = request.host
default_url_options[:port] = request.port unless request.port == 80
protocol = /(.*):\/\//.match(request.protocol)[1] if request.protocol.ends_with?("://")
default_url_options[:protocol] = protocol
end
yield
ensure
::ActionController::UrlWriter.module_eval do
default_url_options[:host] = @old_default_url_options[:host]
default_url_options[:port] = @old_default_url_options[:port]
default_url_options[:protocol] = @old_default_url_options[:protocol]
end
end
end
end
end

module ActionMailer
def self.included(am)
am.send(:include, ::ActionController::UrlWriter)
::ActionController::UrlWriter.module_eval do
default_url_options[:host] = 'localhost'
default_url_options[:port] = 3000
default_url_options[:protocol] = 'http'
end
end
end
end

ActionController::Base.send(:include, UrlWriterRetardaseInhibitor::ActionController)
ActionMailer::Base.send(:include, UrlWriterRetardaseInhibitor::ActionMailer)

0 comments on commit 1203be9

Please sign in to comment.