2

I have been troubleshooting a problem in my Ruby on Rails application for the last 2.5 days. Having used resources online and here on stackoverflow, I've made progress, but still have not resolved the issue.

Quandary: I cannot load the roo gem or the spreadsheet gem into my Rails application.

I have successfully used the spreadsheet gem from the IRB terminal to execute a simple script and output the data read from a spreadsheet to the terminal. This indicates the gem installed correctly and functions correctly.

Nevertheless, Rails doesn't seem to want to recognize these two gems. This comes after many attempts to properly configure the versions of the dependencies and the development dependencies.

My Welcome controller:

class WelcomeController < ApplicationController
    require 'roo'

    def index
        puts "Hello Rails!"
    end
end

My 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'

My roo.gemspec file:

# 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

I tried editing the file to change the spec.require_paths variable as follows:

spec.require_paths = ['lib/roo']

But I had no success after running

>> bundle update
>> bundle install

My path to the roo gem:

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

I'm running LXLE Linux, a Lubuntu derivative.

I have attempted solutions found in these questions, but nothing seems to work for me:

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

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

It seems like I have set my dependencies correctly according to the documentation on rubygems.org.

Has anyone had any issues like this? I've been looking at this issue for the last few days, so perhaps I'm glossing over something that is important, so I thought writing it up and asking about it would help. I'll be spending a few more hours on it today.

Community
  • 1
  • 1
Nathan
  • 21
  • 1
  • 3
  • It's possible this is a Rails 3 vs. Rails 5 thing. Does making a new Rails 5 project and loading in `roo` work as expected? – tadman May 07 '17 at 20:45
  • Hey tadman - I started with a Rails 5.0.2 project, but bundle complained about some of the dependencies of the roo gem when using that version of Rails. Maybe I just need a clean project - I'll try your suggestion. Thanks – Nathan May 07 '17 at 20:55
  • If you can come up with a reproducible problem on a new project running the current version of Ruby you might want to file an issue, though before that be sure to try and experiment with different combinations of things. Hope you can fix it! – tadman May 07 '17 at 20:56
  • Heyo- There seems to be a conflict between Rails 5.0.0 and any version of Rack < 2.0.0: Bundler could not find compatible versions for gem "rack": In Gemfile: rack (~> 1.6) rails (~> 5.0.2) was resolved to 5.0.2, which depends on actionpack (= 5.0.2) was resolved to 5.0.2, which depends on rack (~> 2.0) Since Roo depends on Rack < 2.0.0, it seems like Roo by default will not function correctly with Rails 5.0.0. Am I reading that right? Thanks – Nathan May 08 '17 at 17:11
  • If that's the case, yeah, I'd agree you're reading it right. That's something the Roo team should address. It's possible that restriction is overly paranoid or completely arbitrary, but it's also possible it's actually necessary. It depends if Roo interacts with Rack or not. You may be able to fork Roo and remove that restriction to test that hypothesis. – tadman May 08 '17 at 18:02

1 Answers1

0

Two things you can check:

  • gemset: make sure the gem is installed in the same gemset in which you are in
  • ruby version: make sure the gem is installed in the same ruby version as you are using.

To check, execute 'gem list' from your project directory and see if the gem is listed.

If not in same gemset, you can use:

rvm use gemset_name 

If not in same ruby version, set it to use the ruby version, example 2.3.3

rvm use 2.3.3
slal
  • 2,657
  • 18
  • 29