Taking It to the Next Level
Going back to our renderer implementation, we now understand what happens when we add the following line to our controllers:
â | format.pdf { render pdf: â"contents"â } |
In our renderer, it becomes this:
â | pdf = Prawn::Document.new |
â | pdf.text render_to_string({}) |
â | send_data(pdf.render, filename: â"contents.pdf"â, |
â | disposition: â"attachment"â) |
When we invoke render_to_string with an empty hash, the _normalize_options method in the rendering stack detects the empty hash and changes it to render the template with the same name as the current action. At the end, render_to_string({}) simply passes template: "#{controller_name}/#{action_name}" to the view-renderer object.
The fact that our renderer ...
Get Crafting Rails 4 Applications, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.