[英]Rails.root in lib directory
如何訪問/ lib目錄中的變量RAILS_ROOT
或Rails.root
。 由於某種原因,我得到變量未找到錯誤。
編輯:我嘗試添加
require File.dirname(__FILE__) + '/../config/environment.rb'
推薦給我文件的頂部,這里RAILS_ROOT需要嗎? 但是它仍然給我undefined method root
任何想法,謝謝!
不推薦使用RAILS_ROOT,請改用Rails.root。
ruby-1.9.2-p180 :004 > File.expand_path(File.dirname(__FILE__) + '/config/environment.rb')
=> "/home/lpeabody/Documents/ccom_work/dataserver31/config/environment.rb"
ruby-1.9.2-p180 :005 > require File.expand_path(File.dirname(__FILE__) + '/config/environment.rb')
=> true
ruby-1.9.2-p180 :006 > Rails.root
=> #<Pathname:/home/lpeabody/Documents/ccom_work/dataserver31>
ruby-1.9.2-p180 :007 > RAILS_ROOT
NameError: uninitialized constant RAILS_ROOT
from (irb):7
from /usr/local/rvm/rubies/ruby-1.9.2-p180/bin/irb:16:in `<main>'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.