问题描述
我为我正在启动的 sinatra 应用程序设置了一个项目级 RVM gemset,该应用程序将使用 Active Record 连接到本地数据库.为了测试它,我尝试运行以下测试应用程序:
test.rb
require 'rubygems' # 可能不需要,取决于平台需要'sinatra'需要活动记录"类文章"sqlite3",:数据库 =>硬件数据库")测试第一内容结尾
(摘自这个问题的答案:使用 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': 不能加载这样的文件——activerecord (LoadError)
我已经安装了 Active Record gem,它显示在 gem list
和 rvm current
中显示正确的 gemset.我是 RVM 的新手,我认为这与它没有正确的加载路径有关,但我觉得我已经正确设置了所有内容,因此我很感激有关错误的建议.谢谢.
据我所知 require 'activerecord' 已被弃用.尝试使用
需要'active_record'
相反.
I set up a project level RVM gemset for a sinatra app I am starting that will connect to a local database with Active Record. In order to test it I tried to run the below test app:
test.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
(Taken from the answer to this question: What's the best way to talk to a database while using Sinatra?)
When I run ruby -rubygems test.rb
I get this error:
/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)
I've already installed the Active Record gem and it shows up in gem list
and rvm current
displays the correct gemset. I am new to RVM and I think this is something to do with the it not having the correct load path but I feel like I've set everything up correctly so I'd appreciate suggestions on what's wrong. Thanks.
As far as I can tell require 'activerecord' has been deprecated. Try using
require 'active_record'
instead.
这篇关于使用 RVM 使用 sinatra 应用程序加载 Active Record gem 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!