Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing up ModelRenderer format ambiguity.

  • Loading branch information...
commit edc1928cf9671bdb8f5c1102048676684710f5ae 1 parent ddfafe9
Forrest Zeisler forrest authored
9 README.rdoc
View
@@ -23,8 +23,10 @@ Then run:
Now make a view:
<action name>.pdf.prawn
+
+---
-== Usage
+= Usage
More Details will be coming to {wiki}[http://github.com/forrest/prawnto/wiki].
@@ -62,10 +64,13 @@ Sometimes you need to be able to render a PDF from anywhere (Background process
...
def to_pdf
@x = 1
- Prawnto::ModelRenderer.to_string "test/default_render", self
+ Prawnto::ModelRenderer.to_string "test/default_render.pdf", self
end
end
+<b>Gotcha:</b> Rails isn't always using the correct formatting. If you're having troubles, add the <code>.pdf</code> to the end of the requested template.
+
+---
== Tips
19 lib/prawnto/model_renderer.rb
View
@@ -1,17 +1,26 @@
module Prawnto
module ModelRenderer
+
+ class CustomController < ApplicationController
+ def initialize
+ super
+ self.request = ActionDispatch::Request.new({})
+ self.response = ActionDispatch::Response.new()
+ self.params = {:format => :pdf}
+ end
+ end
+
# template : invoices/show.pdf
# instance_variables : {"@account" => account} - variables set in before filters
def self.to_string(template, calling_object = nil)
- instance = ApplicationController.new
- instance.request = ActionDispatch::Request.new({})
- instance.response = ActionDispatch::Response.new()
-
+ instance = CustomController.new
+
if calling_object
instance.prawnto :inline => true, :instance_variables_from => calling_object
end
- return instance.render_to_string(template, :template => false).html_safe
+ return instance.render_to_string(:action => template, :template => false, :format => :pdf).html_safe
end
+
end
end
2  spec/dummy/app/models/super_model.rb
View
@@ -2,7 +2,7 @@ class SuperModel
def to_pdf
@x = 1
- Prawnto::ModelRenderer.to_string "test/default_render", self
+ Prawnto::ModelRenderer.to_string "test/default_render.pdf", self
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.