module RailsRenderService::ViewHelper

Public Instance Methods

current_layout() click to toggle source
# File lib/rails_render_service/view_helper.rb, line 3
def current_layout
  layout =
    if controller.method(:_layout).arity == 1
      # In Rails 5, this takes the array of formats as an array
      controller.send(:_layout, formats)
    else
      # In earlier Rails, this does not take a format array
      controller.send(:_layout)
    end
  if layout.instance_of? String
    layout
  else
    File.basename(layout.identifier).split('.').first
  end
end
render_service(path) click to toggle source
# File lib/rails_render_service/view_helper.rb, line 18
def render_service(path)
  json = raw render(layout: "layouts/#{current_layout}", template: path, formats: :json)
  Renderer.render_template(json).html_safe
end