我为我正在启动的 sinatra 应用程序设置了一个项目级 RVM gemset,它将使用 Active Record 连接到本地数据库。为了测试它,我尝试运行以下测试应用程序:
测试.rb
require 'rubygems' # may not be needed, depending on platform
require 'sinatra'
require 'activerecord'
class Article < ActiveRecord::Base
end
get '/' do
Test.establish_connection(
:adapter => "sqlite3",
:database => "hw.db"
)
Test.first.content
end
(摘自这个问题的答案:What's the best way to talk to a database while using Sinatra?)
当我运行 ruby -rubygems test.rb
时,我得到了这个错误:
/Users/[user]/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- activerecord (LoadError)
我已经安装了 Active Record gem,它出现在 gem list
中,rvm current
显示正确的 gemset。我是 RVM 的新手,我认为这与它没有正确的加载路径有关,但我觉得我已经正确设置了所有内容,所以我很感激关于错误的建议。谢谢。
最佳答案
据我所知,require 'activerecord' 已被弃用。尝试使用
require 'active_record'
相反。
关于ruby - 使用 RVM 使用 sinatra 应用程序加载 Active Record gem 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8981576/