Pass your request host as a parameter to the mailer method, and then pass it from the method to the view. So, for example, your mail program method may look like this (the example is removed from the docs rails and changed here):
class UserMailer < ActionMailer::Base default :from => "notifications@example.com" def registration_confirmation(user, host) @user = user @host = host mail(:to => user.email, :subject => "Welcome to My Awesome Site") end end
You would call it this way:
def some_action UserMailer.registration_confirmation(@user, request.host).deliver end
Then, in your opinion, you just use @host:
<style type="text/css"> body { background: url(http://<%= @host %>/images/mainbg_repeat.jpg) top repeat-x #cfcfcf; } </style>
All this assumes that the image server is the same as the server on which the request is made. If the image server is located elsewhere, you should output a constant here. You can add something like this in lib / settings.rb:
module Settings IMAGE_HOST = 'superawesome.images.com' end
Then, in your opinion, you simply output a constant, for example:
<style type="text/css"> body { background: url(http://<%= Settings::IMAGE_HOST %>/images/mainbg_repeat.jpg) top repeat-x #cfcfcf; } </style>
Ben Lee Sep 22 '11 at 20:26 2011-09-22 20:26
source share