Created
May 22, 2009 03:49
-
-
Save TheNicholasNick/115916 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# is there a "proper" way to do this? | |
# I want to return a pdf via prince if it is a pdf requested | |
# Otherwise return html reponse | |
class RefCove < Application | |
def show(id, cove_id) | |
provides :pdf, :html | |
@cove = Cove.get(cove_id) | |
raise NotFound if @cove.nil? | |
return display @cove unless params[:format].eql?("pdf") | |
html_string = render("", {:format => :html, :template => "pdf/int", :layout => "pdf"}) | |
html_string.gsub!("src=\'", "src=\'#{Merb.root}/public") | |
prince = Prince.new() | |
prince.add_style_sheets("#{Merb.root}/public/stylesheets/pdf.css") | |
prince.add_style_sheets("#{Merb.root}/public/stylesheets/prince.css") | |
headers.update( | |
"Content-Type" => "application/pdf", | |
"Content-Transfer-Encoding" => "binary" | |
) | |
prince.pdf_from_string(html_string) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment