Princely is generation text/html instead application/pdf?

709 Views Asked by At

I'm using Princely and Rails 3. When I try to render a pdf like this.. respond_to do |format|
format.pdf do
render :pdf => "filename", :template => "path/template.pdf"
end
end

The downloaded file is a text/html format.

How can I fix this and make it work. I have already added the line bellow to config/initializers/mime_types.rb

Mime::Type.register "application/pdf", :pdf

1

There are 1 best solutions below

0
On

I had the same problem yesterday and came across this question in my search for a solution.

In my case, I had the Princely gem installed globally (well, in my global RVM repo) rather than anywhere in my project's directory structure. So none of the Princely code was ever being loaded. I ended up making a new "prince.rb" file in my project's conf/initializers with the following:

require 'princely'
require 'princely/rails'

At that point I still got rails errors because Princely 1.2.5/lib/princely/pdf_helper#stylesheet_file_path refers to ActionView::Helpers::AssetTageHelper, which is apparently a Rails 2ism. I just changed that method's body to "return stylesheet" and then everything worked.

I'm still fairly new to Rails; maybe someone that knows more can chime in with a better way.