Skip to content

Instantly share code, notes, and snippets.

@Joseworks
Forked from tylerhunt/rendering_helper.rb
Created August 10, 2017 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Joseworks/44979dc79d998d7b08546c095249431b to your computer and use it in GitHub Desktop.
Save Joseworks/44979dc79d998d7b08546c095249431b to your computer and use it in GitHub Desktop.
Override Rails' #render helper to fix an issue with rendering partials based on an object within a namespace.
module RenderingHelper
# Override Rails' #render helper to fix an issue with it not honoring objects
# with #to_partial_path definitions that return absolute paths, which is
# problematic when rendering partials within a namespaced controller.
def render(options={}, locals={}, &block)
return super unless options.respond_to?(:to_partial_path)
object = options
path = object.to_partial_path
if path.start_with?('/')
options = { partial: path, object: object, locals: locals }
view_renderer.render_partial(self, options)
else
super
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment