[英]How can I determine if my rails is in the development environment and not the test environment?
I have some code that needs to run only if the rails app is in the development environment (ie $ rails server) but not in the test environment (ie $ rake test).我有一些代码需要在 rails 应用程序处于开发环境(即 $ rails server)而不是在测试环境(即 $ rake test)中时运行。
When I try当我尝试
if Rails.env.development?
dont run me during testing
end
the code gets executed regardless of which environment I am in. I've even tried:无论我在哪个环境中,代码都会被执行。我什至尝试过:
if Rails.env.development? and not Rails.env.test?
NO, REALLY, DONT RUN ME DURING TESTING
end
but no love.但没有爱。
What should I be doing instead?我应该怎么做?
It looks like you're calling it correctly.看起来您正确地调用了它。 Perhaps the problem is that the environment is named differently somewhere.也许问题在于环境在某处的命名不同。 Try in the console:在控制台中尝试:
> Rails.env
=> "development"
> Rails.env.development?
=> true
> Rails.env.test?
=> false
...to confirm that the environment is what you think it is. ...确认环境是您认为的那样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.