Created
April 23, 2014 19:01
-
-
Save illbzo1/11228302 to your computer and use it in GitHub Desktop.
An update to our random_controller for sending HTML to DocRaptor.
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
def show | |
@random = Random.find(params[:id]) | |
respond_to do |format| | |
format.html | |
format.pdf { doc_raptor_send } | |
end | |
end | |
def doc_raptor_send(options = { }) | |
default_options = { | |
:name => controller_name, | |
:document_type => request.format, | |
:test => ! Rails.env.production? | |
} | |
options = default_options.merge(options) | |
options[:document_content] ||= render_to_string | |
ext = options[:document_type] | |
response = DocRaptor.create(options) | |
if response.code == 200 | |
send_data response, :filename => "#{options[:name]}.#{ext}", :type => ext | |
else | |
render :inline => response.body, :status => response.code | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment