在开发环境中Rails delayed_job

时间:2014-04-02 09:24:53

标签: ruby-on-rails email actionmailer

假设你有一个在Rails中有动作的邮件程序,使用delay从某个模型调用,例如:

class ReportMailer < ActionMailer::Base

  default from: "hello@shopstar.co.za"

  def order_received(order)
    @order = order
    mail(:to => @order.shop.email, :subject  => "You have a new order on Shopstar")
  end
end

order.rb:

      if self.shop.email_preference.on_order?
       ReportMailer.delay.order_received(self) unless self.source == "pos"
      end

这会从开发环境发送邮件吗?

这会在生产版本中发送邮件吗?

5 个答案:

答案 0 :(得分:3)

延迟工作的工人需要运行,

用于开发模式运行:

RAILS_ENV=development bin/delayed_job start

在制作中你应该运行:

RAILS_ENV=production bin/delayed_job start

Rails 4 的上述命令,对于 Rails 3 ,您应该这样做:

script/delayed_job代替bin/delayed_job

检查delayed_jobs页面以获取更多details

答案 1 :(得分:0)

这会从开发环境发送邮件吗? 这会在生产版本中发送邮件吗?

全部取决于每个文件中的环境smtp设置(development.rb,production.rb)

要在您的环境中使用延迟作业,需要运行工作人员在后台处理此问题。尝试看看foreman gem来帮助你运行服务器和工人只需使用工头启动。

答案 2 :(得分:0)

如果环境配置未更改,则不会在开发中发送电子邮件,并且会在生产中发送电子邮件。

您应该在config/environments/development.rb中看到类似的内容:

config.action_mailer.perform_deliveries    = false

这可以防止在您的开发环境中发送电子邮件。您可以在configuration guide

中找到有关动作邮件的配置选项的更多详细信息

不要忘记,如果您要延迟发送消息,那么您也需要处理延迟的工作。

答案 3 :(得分:0)

  

这会从开发环境发送邮件吗?

它会根据您的STMP设置发送电子邮件

Rails具有config.action_mailer的设置,您可以在config/environments/development.rb&amp; config/environments/production.rb

  #config/environments/development.rb
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.perform_deliveries = true
  config.action_mailer.smtp_settings = {
      :address              => "smtp.gmail.com",
      :port                 => 587,
      :domain               => "************.co.uk",
      :user_name            => "****@gmail.com",
      :password             => ENV["gmail"],
      :authentication       => :plain,
      :enable_starttls_auto => true
  }
  config.action_mailer.default_url_options = { :host => "localhost:3000"}

无论您运行的是哪个环境delayed_job,都需要确保在环境配置文件中设置了这些详细信息

答案 4 :(得分:0)

首先让我回答您的第二个问题,即从您的系统发送邮件是否实时/开发,您需要smtp设置。对于SMTP设置示例,您可以查看http://guides.rubyonrails.org/action_mailer_basics.html

其次,此配置设置位于其中一个环境文件中。它在哪个环境文件中取决于您的应用程序运行的环境。如果您的实时服务器在开发环境中运行,那么这些更改将在config/environments/development.rb

中进行

希望澄清。

相关问题