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