Rails.env在Rails 2中未定义 [英] Rails.env undefined in Rails 2

查看:106
本文介绍了Rails.env在Rails 2中未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行Ruby on Rails 2.2的旧应用程序,并且我无法使用gem工作,因为它无法使用 Rails.env :

  $ script / console 
>> Rails.env
NoMethodError:未定义的方法`env'for Rails:Module $ b $ from(irb):1

定义 Rails 时,gem设置为使用 Rails.env RAILS_ENV ,当它不是。但是我似乎有一个没有 env 方法的 Rails 对象(尽管我读了Rails 2中添加的方法)。任何想法是怎么回事?

解决方案

Rails 在轨道中。这在3中并不新鲜,因此检查它是否被定义是错误的方法。确定是否可以使用 Rails.env 的正确方法是执行 Rails.respond_to? :env


I have an older application running Ruby on Rails 2.2, and I'm having trouble getting a gem to work because it can't find the current environment with Rails.env:

$ script/console
>> Rails.env
NoMethodError: undefined method `env' for Rails:Module
from (irb):1

The gem is set up to use Rails.env when Rails is defined, and RAILS_ENV when it's not. But I seem to have a Rails object without an env method (even though I read that method was added in Rails 2). Any idea what's going on?

解决方案

The Rails module has always been in rails. It is not new in 3, so checking to see if it's defined is the wrong way to go about things. The correct way to determine if you can use Rails.env is to do Rails.respond_to? :env.

这篇关于Rails.env在Rails 2中未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆