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

发布于 2024-12-19 21:25:32 字数 530 浏览 3 评论 0原文

如何设置我的 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? = true ...

我快到了,但还没有完全...

有什么建议吗,

乔尔

How do I set up my twitter gem not to send tweets in my dev and test environment?

Also I am using Heroku and I don't know how to tell heroku which app is a test which is the prod ...

I followed your tips and added this in my code:

      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

For whatever reason, although I set RACK_ENV= staging and created staging.rb in my environment folder ... I still never managed to get Rails.env.staging? = true ...

I am almost there, but not quite...

any tips,

Joel

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

郁金香雨 2024-12-26 21:25:33

你在使用 Rails 3 吗?您始终可以将只想在一个环境中执行的任何代码包装起来,如下所示:

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

Are you on Rails 3? You can always wrap any code that you only want to execute in one environment like this:

if Rails.env.production?
  #Code here will only execute in your production (Heroku) environment
end
北城挽邺 2024-12-26 21:25:33

有问题吗?与赫罗库。但是您应该将 RACK_ENV 和 RAILS_ENV 配置变量设置为暂存。

There is a problem? with Heroku. But you should set both your RACK_ENV and your RAILS_ENV config variables to staging.

寻找一个思念的角度 2024-12-26 21:25:32

要添加到 Vibhu 的答案...

您需要将代码包装在此

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

然后您需要在 Heroku 上为您的 Heroku 测试/开发服务器指定不同的环境,以便它知道不在该特定 Heroku 服务器上发送任何内容: http://devcenter.heroku.com/articles/multiple-environments

To add to Vibhu's answer...

You need to wrap the code in this

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

And then you need to specify a different environment on Heroku for your Heroku testing / dev server so it knows not to send anything on that specific Heroku server: http://devcenter.heroku.com/articles/multiple-environments

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文