Skip to content

Instantly share code, notes, and snippets.

@tylerhunt
Created March 20, 2015 15:48
Show Gist options
  • Save tylerhunt/3444052625dfee73cf3f to your computer and use it in GitHub Desktop.
Save tylerhunt/3444052625dfee73cf3f 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