As weird as it may sound, the code that generated pdf using Prawn gem in my local version worked successfully, while in online version it shows nothing but empty pdf page. I have also tried changing the environment to "production" in my local version but still unable to reproduce this issue.
The code I use to generate that pdf was:
write_attribute(:filepath, "/reports/#{self.publisher.email}/#{Time.now.to_s(:report_filename)}.#{self.format}")
Prawn::Document.generate(RAILS_ROOT + self.filepath) do |pdf|
titles = self.display_titles
items = self.display_items.map do |item|
titles.collect { |title| item[title.gsub(' ', '')].to_s }
end
pdf.table items, :border_style => :grid,
:row_colors => ["FFFFFF", "DDDDDD"],
:headers => titles,
:align => self.table_aligns
end
Can anybody help, please?
update 1
Running gem list prawn in local version gave me this:
*开发者_Python百科** LOCAL GEMS ***
prawn (0.8.4)
prawn-core (0.8.4)
prawn-layout (0.8.4)
prawn-security (0.8.4)
While running it online gave me:
*** REMOTE GEMS ***
prawn (0.8.4)
prawn-blank (0.0.1)
prawn-core (0.8.4)
prawn-fast-png (0.2.3)
prawn-flexible-table (0.1.2)
prawn-format (0.2.3)
prawn-graph (0.0.4)
prawn-js (0.7.1)
prawn-layout (0.8.4)
prawn-security (0.8.4)
prawn-svg (0.9.1.10)
prawn_commander (0.1.2)
prawn_rails (0.0.4)
prawnto (0.0.3)
Is it a clue to anything at all?
Make sure that you are using the same version of prawn locally and in production.
gem list prawn --local
Note: You may need to check your vendor directory if you have unpacked the gem in either location.
Update
Any errors showing up in the logs on the server?
Also, double-check to make sure that all of the prawn gems that you have installed locally have been unpacked into the vendor directory. If there are any gems that haven't been unpacked, they would work locally because the missing gems would get loaded from the rubygems environment.
I highly recommend using Bundler, as it helps to avoid any dependency resolution issues.
As a friend pointed out, Prawn does not like being Frozen Prawn. Install the gem with sudo to ensure it works.
精彩评论