设置 twitter gem 不在我的开发和测试环境中发送推文
如何设置我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你在使用 Rails 3 吗?您始终可以将只想在一个环境中执行的任何代码包装起来,如下所示:
Are you on Rails 3? You can always wrap any code that you only want to execute in one environment like this:
有问题吗?与赫罗库。但是您应该将 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.
要添加到 Vibhu 的答案...
您需要将代码包装在此
然后您需要在 Heroku 上为您的 Heroku 测试/开发服务器指定不同的环境,以便它知道不在该特定 Heroku 服务器上发送任何内容: http://devcenter.heroku.com/articles/multiple-environments
To add to Vibhu's answer...
You need to wrap the code in this
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