使用RVM西纳特拉的应用程序加载错误的Active Record宝石 [英] Error loading Active Record gem with sinatra app using RVM

查看:189
本文介绍了使用RVM西纳特拉的应用程序加载错误的Active Record宝石的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我成立了一个项目级RVM宝石的西纳特拉的应用程序,我开始将连接到与活动记录的本地数据库。为了测试它,我试图运行下面的测试程序:

test.rb

 需要'rubygems的'#可能不需要,这取决于平台
要求辛纳特拉
需要的ActiveRecord

类文章<的ActiveRecord :: Base的
结束

得到'/'做
  Test.establish_connection(
    :适配器=> sqlite3的,
    :数据库=> hw.db
  )
  Test.first.content
结束
 

(摘自这个问题的答案:什么是同时使用西纳特拉跟一个数据库的最佳方式

当我运行红宝石-rubygems test.rb 我得到这个错误:

<$p$p><$c$c>/Users/[user]/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `需要':无法加载这样的文件 - ActiveRecord的(LoadError)

我已经安装了Active Record的宝石,并将其显示在创业板上市 RVM电流显示正确的宝石。我是新来RVM,我认为这是值得做的是没有正确的负载路径,但我觉得我已经正确设置好一切,所以我倒是对什么是错AP preciate建议。谢谢你。

解决方案

据我可以告诉需要的ActiveRecord'已去precated。尝试使用

 要求'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西纳特拉的应用程序加载错误的Active Record宝石的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆