Skip to content

Instantly share code, notes, and snippets.

@illbzo1
Created April 23, 2014 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save illbzo1/11228302 to your computer and use it in GitHub Desktop.
Save illbzo1/11228302 to your computer and use it in GitHub Desktop.
An update to our random_controller for sending HTML to DocRaptor.
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