Created
March 20, 2015 15:48
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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