Last active
August 29, 2015 14:18
-
-
Save msievers/77c7d2ede569b9c7f0e0 to your computer and use it in GitHub Desktop.
An attempt for a render_relative for rails
This file contains 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
# e.g. inside app/views/records/show.html.erb use | |
# | |
# <%= render_relative "./record/title" %> | |
# | |
# to render app/views/records/show/record/title | |
module App::ApplicationHelper | |
def render_relative(relative_partial_path, locals = {}, &block) | |
calling_file_directory = @virtual_path.split("/")[0..-2].join("/") | |
partial_path = File.join(calling_file_directory, relative_partial_path) | |
render(partial_path, locals, &block) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment