加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby – 使用RVM使用sinatra app加载Active Record gem时出错

发布时间:2020-12-16 20:43:46 所属栏目:百科 来源:网络整理
导读:我为我开始的sinatra应用程序设置了一个项目级别的RVM gemset,它将连接到具有Active Record的本地数据库.为了测试它我尝试运行以下测试应用程序: test.rb require 'rubygems' # may not be needed,depending on platformrequire 'sinatra'require 'activere
我为我开始的sinatra应用程序设置了一个项目级别的RVM gemset,它将连接到具有Active Record的本地数据库.为了测试它我尝试运行以下测试应用程序:

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

(摘自这个问题的答案: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列表中,rvm current显示正确的gemset.我是RVM的新手,我认为这与它没有正确的加载路径有关,但我觉得我已经正确设置了所有内容,所以我很欣赏有关错误的建议.谢谢.

解决方法

据我所知,’activerecord’已被弃用.尝试使用
require 'active_record'

代替.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读