Created
October 26, 2015 16:57
-
-
Save edipofederle/b9ac1e894e1a3da41213 to your computer and use it in GitHub Desktop.
This file contains 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
module Modules | |
class OrderPdf | |
include ActionView::Rendering | |
def initialize(order) | |
@order = order | |
@view = ActionView::Base.new(ActionController::Base.view_paths, {}) | |
@view.extend(ApplicationHelper) | |
@view.extend(AbstractController::Rendering) | |
@view.extend(Rails.application.routes.url_helpers) | |
@save_path = Rails.root.join('public','filename.pdf') | |
end | |
def save | |
File.open(@save_path, 'wb') do |file| | |
file << rendered_pdf | |
end | |
end | |
private | |
def rendered_pdf | |
WickedPdf.new.pdf_from_string(rendered_view) | |
end | |
def rendered_view | |
@view.render_to_string(template: 'orders/show.pdf.erb') | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment