开发者

Princely is generation text/html instead application/pdf?

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 fi开发者_如何学Cle 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜