添加gem docx_converter

时间:2019-05-06 13:19:48

标签: ruby-on-rails rubygems ruby-on-rails-5 publisher

TL; DR:

我应该使用docx gem,而不是(较旧的)docx_converter。这似乎与Rails 5.2更加兼容。


我正在学习Rails,并且有一个有效的应用程序。但是,当我将gem docx_converter添加到我的Gemfile中(以便将Word文件转换为markdown以便进一步处理)时,服务器无法启动。

该应用程序具有三种模型:Company(具有多个用户)和has_many(多个项目)。 (用户由Devise控制,公司通过用户拥有多个项目。)当用户创建项目时,他们可以使用active_storage将文件上传到该项目,并且该文件存储在我的开发环境中的磁盘上(这是我所关心的)在这里)。

我对以上任何内容都没有问题-我可以创建用户和项目,并可以从项目中添加和删除文件。

但是,如果我将gem 'docx_converter'添加到我的Gemfile中并运行bundle update,则无法再运行rails服务器。在此操作之前,一切都很好。之后,服务器将无法运行,回溯(最后几行)为:

    10: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
     9: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/docx_converter-1.0.0/lib/docx_converter.rb:18:in `<main>'
     8: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require'
     7: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
     6: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require'
     5: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:26:in `require'
     4: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:40:in `rescue in require'
     3: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
     2: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:89:in `register'
     1: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
/Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require': cannot load such file -- publishr (LoadError)

鉴于引导程序的引用,我尝试将其从Gemfile和config / boot.rb中删除,但这导致在同一位置(但与发布者有关)的相同错误:

    10: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/bundler-2.0.1/lib/bundler/runtime.rb:65:in `require'
     9: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/bundler-2.0.1/lib/bundler/runtime.rb:65:in `each'
     8: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/bundler-2.0.1/lib/bundler/runtime.rb:76:in `block in require'
     7: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/bundler-2.0.1/lib/bundler/runtime.rb:76:in `each'
     6: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/bundler-2.0.1/lib/bundler/runtime.rb:81:in `block (2 levels) in require'
     5: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/bundler-2.0.1/lib/bundler/runtime.rb:81:in `require'
     4: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/docx_converter-1.0.0/lib/docx_converter.rb:18:in `<top (required)>'
     3: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require'
     2: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:257:in `load_dependency'
     1: from /Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `block in require'
/Users/john/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/activesupport-5.2.3/lib/active_support/dependencies.rb:291:in `require': cannot load such file -- publishr (LoadError)

我尝试通过“ gem install publishr”安装发布服务器,但这无济于事。

我的Gemfile是:

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.6.2'

gem 'rails', '~> 5.2.3'
gem 'puma', '~> 3.11'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.2'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'
gem 'bcrypt', '~> 3.1.7'
gem 'bootsnap', '>= 1.1.0', require: false

# Manually added gems
gem 'will_paginate', '~> 3.1.6'
gem 'devise', '~> 4.6.2'
gem 'cancancan', '~>3.0.1'
gem 'docx_converter', '~>1.0.0'

group :development, :test do
  gem 'sqlite3'
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  gem 'faker', '~> 1.7.3'
end

group :development do
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end

这个gem和Rails 5.2.3似乎存在问题,但是没有人知道这里发生了什么以及如何使它工作吗? (或者,也可以使用其他gem来将Word docx文件转换为可用的文件)

2 个答案:

答案 0 :(得分:0)

bootsnap可能在所有这些方面都可以发挥作用,因为它与Rails的启动混乱。尝试确保清除了所有弹簧过程ps -ef | grep spring。移除bootsnap宝石和bundle install。然后尝试再次rails s启动服务器。

答案 1 :(得分:0)

经过一定数量的钻探后,我发现我需要明确地需要两个额外的gem才能使docx_converter正常工作,并且还必须锁定其中一个的版本。

gem 'publishr'
gem 'rubyzip', '~>0.9.9'
gem 'docx_converter', '~>1.0.0'

我还没有对功能进行详尽的测试,但是至少服务器现在可以启动了!谢谢大家的建议!

编辑

即使在服务器运行后,我也遇到了这个问题-正如@engineersmnky所说,它很旧,文档记录很差。因此,我已切换到docx gem,它并没有尝试做很多事情,但是看起来(a)可以在Rails 5.2上毫无问题地加载并且(b)可以正常工作!