Skip to content

Instantly share code, notes, and snippets.

@msievers
Last active August 29, 2015 14:18
Show Gist options
  • Save msievers/77c7d2ede569b9c7f0e0 to your computer and use it in GitHub Desktop.
Save msievers/77c7d2ede569b9c7f0e0 to your computer and use it in GitHub Desktop.
An attempt for a render_relative for rails
# 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