Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.