Rails 4.1.4,我有很多Mailer類,它們都有不同的傳遞方法。現在這已經導致我一個問題。基於條件的交付方式? Rails
在開發和測試環境的時候,如果我執行和交付使用下面的類,然後交付方式變得:custom_method
,即使我已經提到在軌環境文件config.delivery_method = :test
我已經DELIVERY_METHOD爲:test
然後。
class CustomMailer < ActionMailer::Base
default :delivery_method => :custom_method,
from: "...",
reply_to: '...'
def emailer(emails)
mail(to: emails, subject: 'test')
end
end
什麼是開發和測試環境改變:custom_method
到:test
的正確方法嗎?
一個可能的解決方案,我已經實現了它的工作原理是這樣的:
class CustomMailer < ActionMailer::Base
DELIVERY_METHOD = Rails.env == 'production' ? :custom_method : :test
default :delivery_method => DELIVERY_METHOD,
from: "...",
reply_to: '...'
def emailer(emails)
mail(to: emails, subject: 'test')
end
end
這對我的作品,但我覺得這不是一個好辦法,因爲我必須在此線:
DELIVERY_METHOD = Rails.env == 'production' ? :custom_method : :test
在每個Mailer類中都可能導致冗餘。如果可以通過一些常見的方式處理,那將會很棒。
請注意,有不同交付方法爲每個梅勒類。
更好的方法。 – user1735921