What is the best way to pass the domain name of your rails server for distribution?

I have an application that works in several environments, that is (development, stage, beta, live)

What is the best way to pass the application domain name when sending mail in order to resolve different domain names depending on the server?

My first thought is to add something to the corresponding environment.rb files for each of them, so config/environments/beta.rb will contain

 ActionMailer::Base.smtp_settings[:domain] = 'beta.domain.com' 

And config/environments/staging.rb will contain

 ActionMailer::Base.smtp_settings[:domain] = 'staging.domain.com' 

It seems to me that I'm doing something so that Rails will already have this value, but I did not find it in any of the places that I usually expected, and I can not find it in the documentation.

What is the best approach for this?

+4
source share
2 answers

Usually I just pass the request.host value to the ActionMailer method.

+4
source

In your environment files you want to install:

 ActionMailer::Base.default_url_options = { :host => "beta.domain.com" } 

If you use url_for instead of named routes, you also need to specify: only_path => false ... so you won’t get relative URLs. However, I'm generally trying to use named routes.

+1
source

Source: https://habr.com/ru/post/1286329/


All Articles