Replies: 1 comment 1 reply
-
You might want to take a look at the View extension. You'd also have a bit more separation of concerns with it. class FancyModel
# ...
end
class FancyModelPDF
include Prawn::View
def initialize(model)
@model = model
end
def render
text 'etc..'
text 'more text'
super()
end
end And in the controller: format.pdf do
send_data FancyModelPDF.new(@model).render, filename: "model_#{@model.name}.pdf", type: "application/pdf", disposition: "inline"
end |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In my model I have a simple method:
And in my controller:
This works fine. However I can see myself tiring of constantly having to type:
vs the block method:
From what I see then the local scope is lost and it seem that that block returns the rendered PDF as I just get errors in my controller if I try this method. Already getting tired of constantly typing
pdf.
before everything.Can I modify my existing code to accomplish this?
Beta Was this translation helpful? Give feedback.
All reactions