我正在为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 list | grep -i rails
rails (2.3.4, 2.3.2, 2.2.2, 1.2.6)
答案 0 :(得分: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
答案 1 :(得分:0)
来自@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