【问题标题】:LoadError: cannot load such file -- rooLoadError: 无法加载此类文件 -- roo
【发布时间】:2017-05-07 20:14:48
【问题描述】:

在过去的 2.5 天里,我一直在对我的 Ruby on Rails 应用程序中的一个问题进行故障排除。使用了在线资源和 stackoverflow 上的资源后,我取得了进展,但仍未解决问题。

困惑:我无法将 roo gem 或电子表格 gem 加载到我的 Rails 应用程序中。

我已成功使用 IRB 终端中的电子表格 gem 来执行一个简单的脚本,并将从电子表格中读取的数据输出到终端。这表明 gem 安装正确并且功能正常。

尽管如此,Rails 似乎并不想识别这两个宝石。这是在多次尝试正确配置依赖项和开发依赖项的版本之后发生的。

我的欢迎控制器:

class WelcomeController < ApplicationController
    require 'roo'

    def index
        puts "Hello Rails!"
    end
end

我的Gemfile

source 'https://rubygems.org'

git_source(:github) do |repo_name|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
  "https://github.com/#{repo_name}.git"
end


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 4.2.8'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a     debugger console
  gem 'byebug', platform: :mri
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %>     anywhere in the code.
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '~> 3.0.5'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

gem 'minitest', '~> 5.4'

gem 'rack', '~> 1.6'

gem 'nokogiri'

gem 'ruby-ole'

gem 'hoe', '~> 3.14'

gem 'rdoc', '~> 4.0'

gem 'roo', '2.7.0'

gem 'spreadsheet', '1.1.0'

我的 roo.gemspec 文件:

# encoding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'roo/version'

Gem::Specification.new do |spec|
  spec.name          = 'roo'
  spec.version       = Roo::VERSION
  spec.authors       = ['Thomas Preymesser', 'Hugh McGowan', 'Ben Woosley', 'Oleksandr Simonov', 'Steven Daniels']
  spec.email         = ['ruby.ruby.ruby.roo@gmail.com', 'oleksandr@simonov.me']
  spec.summary       = 'Roo can access the contents of various spreadsheet files.'
  spec.description   = "Roo can access the contents of various spreadsheet files. It can handle\n* OpenOffice\n* Excelx\n* LibreOffice\n* CSV"
  spec.homepage      = 'http://github.com/roo-rb/roo'
  spec.license       = 'MIT'

  spec.files         = `git ls-files -z`.split("\x0")
  spec.files.reject! { |fn| fn.include?('test/files') }
  spec.require_paths = ['lib']

  spec.add_dependency 'nokogiri', '~> 1'
  spec.add_dependency 'rubyzip', '~> 1.1', '< 2.0.0'

  spec.add_development_dependency 'rake', '~> 10.1'
  spec.add_development_dependency 'minitest', '~> 5.4', '>= 5.4.3'
  spec.add_development_dependency 'rack', '~> 1.6', '< 2.0.0'
end

我尝试编辑文件以更改 spec.require_paths 变量,如下所示:

spec.require_paths = ['lib/roo']

但是我跑了之后没有成功

>> bundle update
>> bundle install

我的 roo gem 之路:

/var/lib/gems/2.3.0/gems/roo-2.7.0/

我正在运行 LXLE Linux,它是 Lubuntu 的衍生产品。

我已尝试在这些问题中找到解决方案,但似乎对我没有任何帮助:

Ruby roo LoadError: cannot load such file -- spreadsheet/note

cannot load such file -- sqlite3/sqlite3_native (LoadError) on ruby on rails

看来我已经根据 ruby​​gems.org 上的文档正确设置了我的依赖项。

有人遇到过这样的问题吗?过去几天我一直在研究这个问题,所以也许我在掩盖一些重要的事情,所以我认为写下来并询问它会有所帮助。今天我会再花几个小时。

【问题讨论】:

  • 这可能是 Rails 3 与 Rails 5 的对比。创建一个新的 Rails 5 项目并加载 roo 是否按预期工作?
  • 嘿 tadman - 我从一个 Rails 5.0.2 项目开始,但在使用该版本的 Rails 时,bundle 抱怨 roo gem 的一些依赖项。也许我只需要一个干净的项目 - 我会尝试你的建议。谢谢
  • 如果您可以在运行当前版本的 Ruby 的新项目上提出可重现的问题,您可能需要提交问题,但在此之前请务必尝试并尝试不同的组合。希望你能解决它!
  • Heyo-Rails 5.0.0 和任何版本的 Rack 1.6) rails (~> 5.0.2) 被解析为 5.0.2,它依赖于 actionpack (= 5.0.2) 被解析为 5.0.2,它依赖于 rack (~> 2.0) 因为 Roo 依赖于 Rack
  • 如果是这样的话,是的,我同意你没看错。这是 Roo 团队应该解决的问题。限制可能过于偏执或完全武断,但也有可能实际上是必要的。这取决于 Roo 是否与 Rack 交互。您也许可以分叉 Roo 并删除该限制以检验该假设。

标签: ruby-on-rails ruby ruby-on-rails-3 rubygems


【解决方案1】:

您可以检查两件事:

  • gemset:确保 gem 安装在您所在的 gemset 中
  • ruby 版本:确保 gem 安装在与您使用的 ruby​​ 版本相同的版本中。

要检查,请从您的项目目录中执行“gem list”并查看 gem 是否已列出。

如果不在同一个 gemset 中,您可以使用:

rvm use gemset_name 

如果不在同一个ruby版本,设置为使用ruby版本,例如2.3.3

rvm use 2.3.3

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-30
    • 2015-01-22
    • 2012-10-25
    • 2020-12-05
    • 2017-03-18
    • 2018-07-31
    • 2015-03-20
    相关资源
    最近更新 更多