Skip to content

Instantly share code, notes, and snippets.

@illbzo1
Created April 23, 2014 19:01

Revisions

  1. Tyler Moore created this gist Apr 23, 2014.
    25 changes: 25 additions & 0 deletions random_controller.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    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