ruby on rails - Rails3: rewrite url_for for subdomain support, how to extend action mailer to use such url_for -


i take code subdomain railscast

module urlhelper   def with_subdomain(subdomain)     subdomain = (subdomain || "")     subdomain += "." unless subdomain.empty?     [subdomain, request.domain, request.port_string].join   end    def url_for(options = nil)     if options.kind_of?(hash) && options.has_key?(:subdomain)       options[:host] = with_subdomain(options.delete(:subdomain))     end     super   end end  class applicationcontroller < actioncontroller::base   include urlhelper end   

it ok use modified url_for in views of controllers. have trouble actionmailer.

i tried use following:

class notifier < actionmailer::base   include urlhelper end 

but actionmailer views still use old unmodified url_for actiondispatch::routing::routeset.

what best practice add new url_for

add following code file app/helpers/url_helper.rb:

def set_mailer_url_options     actionmailer::base.default_url_options[:host] = with_subdomain(request.subdomain) end 

and modify file app/controllers/application_controller.rb add:

before_filter :set_mailer_url_options 

source


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -