2017-05-07 55 views
0

我在过去的2.5天里一直在解决Ruby on Rails应用程序中的一个问题。在线上使用资源并在这里使用了stackoverflow,我已经取得了进展,但仍然没有解决问题。LoadError:无法加载这样的文件 - roo

窘境:我无法将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   = ['[email protected]', '[email protected]'] 
    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的宝石后,没有成功:

/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

好像我已按有关RubyGems的文档正确设置我的依赖.ORG。

有没有人有这样的问题?过去几天我一直在研究这个问题,所以也许我会重申一些重要的东西,所以我认为写它并询问它会有所帮助。今天我会花更多的时间在上面。

+0

这是可能的,这是一个Rails 3与Rails 5的东西。按照预期制作新的Rails 5项目并加载“roo”是否工作正常? – tadman

+0

Hey tadman - 我从一个Rails 5.0.2项目开始,但是在使用Rails版本时,bundle抱怨了一些roo gem的依赖关系。也许我只需要一个干净的项目 - 我会尝试你的建议。谢谢 – Nathan

+0

如果您在运行当前版本的Ruby的新项目中遇到可重现问题,则可能需要提交问题,但在此之前请务必尝试并尝试不同的组合。希望你能解决它! – tadman

回答

0

有两件事情你可以检查:

  • 宝石:确保创业板安装在其中你在
  • 红宝石版相同的宝石:确保创业板安装在同一红宝石版本正如你使用的那样。

要检查,执行您的项目目录中的'宝石列表',看看是否列出了宝石。

如果不是在同一个宝石,你可以使用:

rvm use gemset_name 

如果不是在同一个红宝石版本,将其设置为使用红宝石版本,例如2.3.3

rvm use 2.3.3 
相关问题