3
我刚刚添加了导出到PDF使用wicked_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
宝石,以及运行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:尝试卸载并重新安装所有的宝石文件,仍然没有好。
嗯。当宝石作者从rubygems中取出他们的宝石版本时,我见过这种情况,但奇怪的是11.3.0似乎在rubygems上。你的gemfile是什么样的? – steel
用Gemfile更新了问题。 –
好的,嫌疑人#2是wkhtmltopdf。这是一个二进制依赖项,必须安装用于恶意pdf才能工作。你可能已经在本地安装了它,但你是否已经在生产中安装了它? – steel