【发布时间】:2017-04-15 14:30:07
【问题描述】:
我刚刚使用wicked_pdf gem 将导出到PDF 添加到我的应用程序中。它在我的开发机器上运行良好,但在生产服务器上不断抛出以下错误:
I, [2016-12-01T03:40:46.110058 #2857] INFO -- : Rendered reports/summary_of_reports.pdf.erb within layouts/pdf.html (24.3ms)
I, [2016-12-01T03:40:46.779291 #2857] INFO -- : Completed 500 Internal Server Error in 698ms (ActiveRecord: 5.3ms)
F, [2016-12-01T03:40:46.780418 #2857] FATAL -- :
RuntimeError (Failed to execute:
["/home/ams/itdc_accounts/shared/bundle/ruby/2.3.0/bin/wkhtmltopdf", "-q", "file:////tmp/wicked_pdf20161201-2857-1deugco.html", "/tmp/wicked_pdf_generated_file20161201-2857-1snx0mz.pdf"]
Error: PDF could not be generated!
Command Error: /home/ams/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/definition.rb:179:in `rescue in specs': Your bundle is locked to rake (11.3.0), but that version could not be found in any of the sources listed in your Gemfile. If you haven't changed sources, that means the author of rake (11.3.0) has removed it. You'll need to update your bundle to a different version of rake (11.3.0) that hasn't been removed in order to install. (Bundler::GemNotFound)
from /home/ams/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/definition.rb:173:in `specs'
from /home/ams/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/definition.rb:233:in `specs_for'
from /home/ams/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/definition.rb:222:in `requested_specs'
from /home/ams/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:118:in `block in definition_method'
from /home/ams/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/runtime.rb:19:in `setup'
from /home/ams/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler.rb:99:in `setup'
from /home/ams/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/setup.rb:20:in `<top (required)>'
from /usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
):
app/controllers/reports_controller.rb:19:in `block (2 levels) in summary_of_reports'
app/controllers/reports_controller.rb:15:in `summary_of_reports'
问题是我已经尝试使用 Rails 控制台在生产服务器上生成示例 PDF 并且它可以工作,所以我真的很困惑为什么这不起作用。
#view
<%= link_to icon("file-pdf-o") + " Export as PDF", request.parameters.merge({format: :pdf}), target: "_blank" %>
#controller
def summary_of_reports
if params[:at].present?
@account_type = AccountType.find_by_id(params[:at])
@accounts_total = Account.where(account_type: params[:at]).joins(:user).order('users.last_name')
@accounts = Account.where(account_type: params[:at]).joins(:user).order('users.last_name').paginate(page: params[:page], per_page: 30)
end
respond_to do |format|
format.html
format.csv { send_data Account.to_csv(@accounts_total), filename: "summary_of_reports_#{Time.now.strftime("%^b-%d-%Y-%H-%M")}.csv" }
format.pdf do
render pdf: "summary_of_reports_#{Time.now.strftime("%^b-%d-%Y-%H-%M")}",
template: "reports/summary_of_reports.pdf.erb",
locals: {
accounts: @accounts_total,
account_type: @account_type
}
end
end
end
我已经尝试卸载并重新安装 rake 和 bundler gems,以及在服务器端运行 bundle install 和 bundle update 都没有用。
更新: 添加了 Gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.6'
# Use mysql as the database for Active Record
gem 'mysql2', '>= 0.3.13', '< 0.5'
# 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.1.0'
# 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 following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# 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'
gem 'rspec-rails'
gem 'factory_girl_rails'
gem 'capybara'
gem 'database_cleaner'
gem 'selenium-webdriver'
gem 'ffaker'
gem 'shoulda-matchers'
gem 'shoulda-callback-matchers'
gem 'simplecov', :require => false
gem 'capistrano'
gem 'capistrano-bundler'
gem 'capistrano-rails'
gem 'capistrano-rbenv'
gem 'capistrano-passenger'
gem 'rails-erd'
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'thin'
end
gem 'simple_form'
gem 'momentjs-rails', :github => 'derekprior/momentjs-rails'
gem 'datetimepicker-rails', github: 'zpaulovics/datetimepicker-rails', branch: 'master', submodules: true
gem 'font-awesome-sass'
gem 'bootstrap'
# gem 'bootstrap-sass'
gem 'google-webfonts-rails'
gem 'will_paginate'
gem 'will_paginate-bootstrap4'
gem 'devise'
gem 'devise_invitable'
gem 'omniauth'
gem 'omniauth-google-oauth2'
gem 'figaro'
gem 'searchkick'
gem 'wicked_pdf'
gem 'wkhtmltopdf-binary'
更新 2:尝试卸载并重新安装所有 gem 文件,仍然不行。
【问题讨论】:
-
嗯。我已经看到当一个 gem 作者从 rubygems 中拉出他们的 gem 版本时发生这种情况,但奇怪的是 11.3.0 似乎在 rubygems 上。你的 gemfile 是什么样的?
-
用 Gemfile 更新了问题。
-
好的,怀疑 #2 是 wkhtmltopdf。这是一个二进制依赖项,必须安装 wicked pdf 才能工作。您可能已经在本地安装了它,但您是否在生产环境中安装了它?
-
是的,我使用
wkhtmltopdf-binarygem 安装了它。 -
挠头。韦尔普。我搜索了您的错误“您的捆绑包已锁定为 rake (11.3.0),但找不到该版本”。其他人也遇到过你的问题,但我没有看到灵丹妙药。以下是一些尝试解决方案的资源:@987654321@、github.com/ruby/rake/issues/172、github.com/bundler/bundler/issues/5068。
标签: ruby-on-rails rake bundler wkhtmltopdf wicked-pdf