I have a static set of help pages that I serve in a Rails 3.2 application using Thoughbots high-voltage gem. I'm just using this in a 'vanilla' way, without serving up the html pages via the controller.
Background
I had originally tried to do this myself adapting Michael Hartl's tutorial around static pages - i.e I have a set of static pages with their own controller, and I was trying to create a sub-directory under the static pages view, but could not get my routing to work, so Google searches revealed Thoughbots High-Voltage gem.
Aspiration
What I would like is a recommendation of what gem or method is best to generated PDF files using Thoughtbots High-Voltage gem.
Has anybody done this?
I want to be able to host this on heroku so if there are any gotacha's
I'd like to know about these up front.
My current implementation is a basic Rails 3.2 application with the High-Voltage gem installed and a number of views under the pages sub-directory.
I have images within my html pages, not sure if this causes complications.
EDIT: Added controller based on answer provided as still having issues with wicked_pdf on Rails 3.2.3, ruby 1.9.3-p125 on Lion
class PagesController < HighVoltage::PagesController
def show
respond_to do |format|
format.html do
super
end
format.pdf do
#render :pdf => "pdf_file" # wicked_pdf syntax here
render :pdf => :id,
:layout => 'application',
#:template => 'help/products/product_tolerance.html.erb',
:template => 'pages/#{:id}.html.erb',
:show_as_html => params[:debug],
:footer => {
:left => "Generated on @now",
:centre => "Centre",
:right => "Page # of page(s)"
}
end
end
end
end
Routes file contains:
match "/pages/*id" => 'pages#show', :as => :page, :via => :get, :format => false
Should the :format be true? In the controller and in high_voltage?
Override the High Voltage pages controller as described here: https://github.com/thoughtbot/high_voltage#override
Then install either pdfkit or wicked_pdf (html to pdf converters) and hook them into that controller to create PDF versions:
class PagesController < HighVoltage::PagesController
def show
respond_to do |format|
format.html do
super
end
format.pdf do
render :pdf => "pdf_file" # wicked_pdf syntax here
end
end
end
end