ruby-on-rails - 如何在 Rails 的 ERB 文件中检查开发或生产?

标签 ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.2 development-environment production-environment

如果在生产中,我想通过 Google CDN 加载 jQuery UI,如果在开发中,我想在本地加载。所以在我的 application.html.erb 布局中,我必须知道我是在生产中还是在开发中。有我可以检查的变量吗?

最佳答案

为了扩展 Paritosh 的回答,Rails.env.production?Rails.env.development?将根据您使用的环境返回真/假。

这些方法在 StringInquirer 中定义。 ActiveSupport 中的类模块。见他们here .

关于ruby-on-rails - 如何在 Rails 的 ERB 文件中检查开发或生产?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12646495/

相关文章:

ruby-on-rails - 为一个没有路由的操作编写一个失败的测试,即使 Assets 管道打开

ruby-on-rails - 如何定义 allow_destroy 和 :dependent => :destroy in Rails?

ruby-on-rails - Rails 如何根据日期范围创建月份数组

ruby-on-rails - Gmaps4Rails : How to open the Infowindow of the single marker by default when the Google maps is loaded (without clicking on the marker)

mysql - Rails 没有使用 database.yml 中提供的密码

ruby-on-rails - 使用 ActiveRecord 和 Rails 将数据插入 postgresql 数据库出现此错误 : RuntimeError: ERROR C22003 Minteger o

jquery - Rails 3.1 原型(prototype)-rails

ruby-on-rails - 如何在模型中调用 ApplicationController 中定义的方法

ruby-on-rails - 如何使用 RSpec 测试 Pusher

ruby-on-rails - 什么时候适合在 Rails 2.1 中使用 Time#utc?