我正在为CloudCrowd编写一个“操作”,它需要访问Rails环境(对于一些ActiveRecord内容),但是加载环境的标准方法会导致可疑的错误。
我在我的操作.rb文件的顶部尝试了以下每一项:
require(File.join(File.dirname(__FILE__), '../..', 'boot'))
和
require File.expand_path(File.dirname(__FILE__) + "/../../environment")
当我尝试启动节点时,我得到了这个错误:
»crowd node
Starting CloudCrowd Node on port 9063...
Missing the Rails 2.3.2 gem. Please `gem install -v=2.3.2 rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.
当然,我已经安装了gem:
»gem list | grep -i rails
rails (2.3.4, 2.3.2, 2.2.2, 1.2.6)
发布于 2009-11-06 20:34:52
@documentcloud的某个人看到了我的请求,并帮助我解决了这个问题。我必须在动作脚本前加上this前缀
RAILS_GEM_VERSION = nil
RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '../../..'))
RAILS_ENV = ENV['RAILS_ENV'] || 'development'
if CloudCrowd.node?
require 'rubygems'
require 'activerecord'
ActiveRecord::Base.logger = Logger.new(STDOUT)
require File.expand_path(File.join(File.dirname(__FILE__), '../..', 'environment'))
end
发布于 2010-01-25 18:41:55
好的!实际上,我在使用RAILS_ROOT路径时遇到了一些问题,并将其替换为'../../..‘使用“../..”。此外,由于您已经声明了RAILS_ROOT常量,因此可以在环境要求中去掉一些东西。以下是我的版本:
RAILS_GEM_VERSION = nil
RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '../..'))
RAILS_ENV = ENV['RAILS_ENV'] = ENV['RACK_ENV']
if CloudCrowd.node?
require 'rubygems'
require 'activerecord'
ActiveRecord::Base.logger = Logger.new(STDOUT)
require "#{RAILS_ROOT}/config/environment"
# and if you need to import
# anything from lib just go ahead and
require 'my_custom_lib/name_of_file'
end
https://stackoverflow.com/questions/1689699
复制相似问题