需要RAILS_ROOT吗? [英] RAILS_ROOT require?

查看:134
本文介绍了需要RAILS_ROOT吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试访问/lib目录中的文件中的RAILS_ROOT常量,但无法执行(未初始化的常量错误).我需要具备某些功能才能做到这一点吗?

I'm trying to access the RAILS_ROOT constant in a file residing in the /lib directory, but I'm not able to (uninitialized constant error). Is there something that I need to require to be able to do this?

推荐答案

是的,您应该要求使用environment.rb:

Yes, you should require the environment.rb:

require File.dirname(__FILE__) + '/../config/environment.rb'
puts RAILS_ROOT

Rails.root.

这篇关于需要RAILS_ROOT吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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