未初始化常量 RAILS_ROOT:Surveyor gem 并使用 Rails.root

Uninitialized constant RAILS_ROOT: Surveyor gem and using Rails.root

我正在尝试使用 the installation guide provided. I am working from the surveyor-example that is available here 设置测量员 gem,所以我假设我会使用旧代码。然而,当我 运行

bundle exec rake surveyor FILE=surveys/kitchen_sink_survey.rb

出现错误"uninitialized constant RAILS_ROOT"。我 read here 解决这个问题的方法是尝试使用 Rails.root,但我不确定在哪里更改此设置。这是我在 environment.rb 中设置的还是在调查代码中设置的?

如果它提供了任何进一步的帮助,跟踪结果如下:

/home/nitrous/surveyor_example/.bundle/bundler/gems/surveyor-a95169e36afc/lib/tasks/surveyor_tasks.rake:7:in `block (2 levels) in <top (required)>'
/home/nitrous/surveyor_example/.bundle/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
/home/nitrous/surveyor_example/.bundle/gems/rake-0.9.2/lib/rake/task.rb:205:in `block in execute'
/home/nitrous/surveyor_example/.bundle/gems/rake-0.9.2/lib/rake/task.rb:200:in `each'
/home/nitrous/surveyor_example/.bundle/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
/home/nitrous/surveyor_example/.bundle/gems/rake-0.9.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/usr/local/opt/rbenv/versions/2.1.5/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/home/nitrous/surveyor_example/.bundle/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/home/nitrous/surveyor_example/.bundle/gems/rake-0.9.2/lib/rake/task.rb:176:in `block in invoke_prerequisites'
/home/nitrous/surveyor_example/.bundle/gems/rake-0.9.2/lib/rake/task.rb:174:in `each'
/home/nitrous/surveyor_example/.bundle/gems/rake-0.9.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/home/nitrous/surveyor_example/.bundle/gems/rake-0.9.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain'
/usr/local/opt/rbenv/versions/2.1.5/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/home/nitrous/surveyor_example/.bundle/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/home/nitrous/surveyor_example/.bundle/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
/home/nitrous/surveyor_example/.bundle/gems/rake-0.9.2/lib/rake/application.rb:112:in `invoke_task'
/home/nitrous/surveyor_example/.bundle/gems/rake-0.9.2/lib/rake/application.rb:90:in `block (2 levels) in top_level'
/home/nitrous/surveyor_example/.bundle/gems/rake-0.9.2/lib/rake/application.rb:90:in `each'
/home/nitrous/surveyor_example/.bundle/gems/rake-0.9.2/lib/rake/application.rb:90:in `block in top_level'
/home/nitrous/surveyor_example/.bundle/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/home/nitrous/surveyor_example/.bundle/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level'
/home/nitrous/surveyor_example/.bundle/gems/rake-0.9.2/lib/rake/application.rb:62:in `block in run'
/home/nitrous/surveyor_example/.bundle/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/home/nitrous/surveyor_example/.bundle/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
/home/nitrous/surveyor_example/.bundle/gems/rake-0.9.2/bin/rake:32:in `<top (required)>'
/home/nitrous/surveyor_example/.bundle/bin/rake:23:in `load'
/home/nitrous/surveyor_example/.bundle/bin/rake:23:in `<main>'

错误来自您使用的测量员 gem 版本。 surveyor-a95169e36afc 指的是旧版本。

在你的 Gemfile 中确保你只有

gem 'surveyor'

bundle install

设置后,它应该安装 surveyor 0.20.0,它将与您的 rails.

版本一起使用

教程中包含的 Gemfile 是 date/for 不同版本的 rails。