0

我正在为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)
4

2 回答 2

1

好的!我实际上在您的 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
于 2010-01-25T18:41:54.957 回答
0

@documentcloud 的某个人看到了我的请求并帮助我解决了这个问题。必须在动作脚本前加上这个

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
于 2009-11-06T20:34:52.017 回答