I've used Prawnto quite a bit in a few Rails projects. As I'm trying to integrate it into this project, I'm unable to get it working!
I've installed the plugin, and the files are there:
script/plugin install git://github.com/thorny-sun/prawnto.git
I've added this line to environment.rb in the config block:
config.gem "prawn"
Prawn is installed as a gem and configured:
gem list --local
prawn (0.5.1)
prawn-core (0.5.1)
prawn-format (0.2.1)
prawn-layout (0.2.1)
...among others.
And lastly, I've set up my controller method to handle the PDF:
def print
@report = Report.find(params[:id])
prawnto :filename => @report.name + ".pdf", :inline => false
end
The result? A "Template Missing" error. It's looking for "print.erb". I have the view file named "print.prawn.pdf", and no other view files with the same name.
I've spent a couple hours on this, with no luck whatsoever. Any po开发者_JS百科inters you could provide would be appreciated!
Cheers, Aaron.
Here's an update. There appears to be two ways to invoke Prawnto: as I stated above using the "prawnto" method call, and via a respond_to block, like so:
def print
@report = Report.find(params[:id])
respond_to do |format|
format.pdf
end
end
Now, THIS works. Is this still using Prawnto? Or something else? I'm just throwing my hands up at this point.
Thanks, Aaron.
I haven't used Prawnto, but can you specify the template in the prawnto method call?
prawnto :filename => @report.name + ".pdf", :inline => false, :template => "print.prawn.pdf"
I would recommend checking out out Wicked PDF as an alternative if you are still having trouble.
I have the view file named "print.prawn.pdf"
And I have view file named "print.pdf.prawn", and it works with blank controller method. (I'm using rails 2.3.8 and the same prawn config as you)
精彩评论