Skip to content

Instantly share code, notes, and snippets.

@labocho
Created April 20, 2021 06:32
Show Gist options
  • Save labocho/b746528446b547ef87fdb540103b2598 to your computer and use it in GitHub Desktop.
Save labocho/b746528446b547ef87fdb540103b2598 to your computer and use it in GitHub Desktop.
Rails view renderer
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