哪一个更好的做法是在rails中发送电子邮件?

时间:2015-05-29 17:30:02

标签: ruby-on-rails ruby

我有关于发送电子邮件的FakeMailer类。

class FakeMailer < ActionMailer::Base
  def fake_method_1(recipient, subject)
    mail(to: email, subject: "#{Rails.env} - #{message}", body: body).deliver
  end

  def fake_method_2(recipient, subject)
    mail(to: email, subject: "#{Rails.env} - #{message}", body: body)
  end

end

fake_method_1和fake_method_2都发送了相同的电子邮件。我能做到

FakeMailer.fake_method_1(recipient, subject)
FakeMailer.fake_method_2(recipient, subject).deliver

哪一个是更好的做法?换句话说,我应该返回一个邮件实例,然后直接从FakeMailer类交付或交付吗?有什么权衡?

由于

2 个答案:

答案 0 :(得分:2)

第二种选择。如果有一天你想deliver_later而不是呢?我确定还有其他原因不能在方法中调用deliver

答案 1 :(得分:0)

第二个。我尝试使用第一种方法但它没有用。我认为这是因为邮件超出了范围。