I have this in my controller. I need my view to generate some HTML, which I then convert to a pdf using Flying Saucer (Im using JRuby). This then gets returned to the client.
def show
@cs_agreement = CsAgreement.find(params[:id])
respond_to do |format|
format.pdf do
# TODO there must be a better way of getting the path to the view!
report_template = ERB.new(File.new("app/views/agreement_document/client_agreement.erb"), nil, "%<")
created_report = report_template.result(binding)
send_data( FlyingSaucer::create_pdf(created_report), :filename => "agreement.pdf",
:type => "application/pdf",
:disposition => 'inline')
end
end
This is the best I can do... I can only work out how to use ERB to manually generate the html so I can retreive the data to send to FlyingSaucer before returning.
This way also seems to mean I cant access any of the Helper methods.
Is there no way I can get rails to generate the html for me and somehow intercept it to convert to pdf before returning? The render function seems to just generate and return all in one..