设置twitter gem不要在我的开发和测试环境上发送推文

时间:2011-12-06 22:01:33

标签: ruby-on-rails twitter heroku development-environment production-environment

如何设置我的twitter gem不要在我的开发和测试环境中发送推文?

此外我正在使用Heroku,我不知道如何告诉heroku哪个应用程序是一个测试,这是生产...

我按照您的提示将其添加到我的代码中:

      if Rails.env.staging? 
        Notifier.send_email(msg)
      elsif Rails.env.production?
        Twitter.update(msg)
      else
        logger.info "JOEL - #msg}"
        Notifier.send_email(msg)
      end

无论出于何种原因,虽然我设置了RACK_ENV = staging并在我的环境文件夹中创建了staging.rb ...我仍然没有设法获得Rails.env.staging? =真......

我快到了,但不是很......

任何提示,

乔尔

3 个答案:

答案 0 :(得分:2)

你是否在Rails 3上?您始终可以在以下环境中包装您只想执行的任何代码:

if Rails.env.production?
  #Code here will only execute in your production (Heroku) environment
end

答案 1 :(得分:2)

添加到Vibhu的答案......

您需要将代码包装在此

if Rails.env.production?
  # Code here will only execute in your production environment
end

然后你需要为Heroku测试/ dev服务器在Heroku上指定一个不同的环境,这样它就知道不能在特定的Heroku服务器上发送任何东西:http://devcenter.heroku.com/articles/multiple-environments

答案 2 :(得分:0)

有问题吗?与Heroku。但是你应该将RACK_ENV和RAILS_ENV配置变量都设置为暂存。