Created
April 20, 2021 06:32
-
-
Save labocho/b746528446b547ef87fdb540103b2598 to your computer and use it in GitHub Desktop.
Rails view renderer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ViewRenderer | |
| class ViewRenderingController < ActionController::Base | |
| include Rails.application.routes.url_helpers | |
| include ApplicationHelper | |
| def protect_against_forgery? | |
| false | |
| end | |
| end | |
| def self.render_to_string(template, options = {}) | |
| new.render_to_string(template, options) | |
| end | |
| def initialize | |
| @renderer = ViewRenderingController.renderer | |
| end | |
| def render_to_string(template, options = {}) | |
| @renderer.render({template: template}.merge(options)) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment