Permalink
Browse files

Fixing up ModelRenderer format ambiguity.

  • Loading branch information...
1 parent ddfafe9 commit edc1928cf9671bdb8f5c1102048676684710f5ae @forrest forrest committed Jan 22, 2012
Showing with 22 additions and 8 deletions.
  1. +7 −2 README.rdoc
  2. +14 −5 lib/prawnto/model_renderer.rb
  3. +1 −1 spec/dummy/app/models/super_model.rb
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
@@ -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,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

0 comments on commit edc1928

Please sign in to comment.