[英]rails 4 ruby conditional based on ENV var and Rails.env.production?
I am trying to setup a few global helper decision functions that look like this: 我正在尝试设置一些如下所示的全局帮助程序决策函数:
def send_email_to_external_service
ENV['SEND_EMAIL_TO_EXTERNAL_SERVICE']? true : false
end
This works great for development, but obviously, I do not want to have to pass these parameters in for production so I had to roll with: 这对开发非常有用,但是显然,我不想在生产中传递这些参数,因此我不得不:
def send_email_to_external_service
active = ENV['SEND_EMAIL_TO_EXTERNAL_SERVICE']? true : false
active = true if Rails.env.production?
return active
end
Would there be a better way of structuring this function ie is a single line possible? 有没有更好的方法来构造此功能,即单行可能吗?
I would just do something like this: 我会做这样的事情:
def send_email_to_external_service
Rails.env.production? || ENV['SEND_EMAIL_TO_EXTERNAL_SERVICE']
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.