I am using a (primary) partial:
<%= render partial: 'shared/page/head' %>
Which makes use of other (secondary) partials:
<head>
<%= render partial: 'shared/page/head/title' %>
<%= render partial: 'shared/page/head/meta' %>
...
<%= render partial: 'shared/page/head/fonts' %>
...
<%= render partial: 'shared/page/head/google_analytics' %>
</head>
As you can see I'm currently using paths relative to app/view
for these secondary partials even though they are sitting in the same directory as the primary partial.
I've tried using relative paths:
<%= render partial: 'title' %>
Or
<%= render partial: './title' %>
But neither work.
Is there a way to have a partial resolve partials it uses using a relative path?
A relative path refers to a location that is relative to a current directory. Relative paths make use of two special symbols, a dot (.) and a double-dot (..), which translate into the current directory and the parent directory. Double dots are used for moving up in the hierarchy.
Yes. The current working directory is a property of the process.
When relative paths are supported, the File Browser provides a Relative Path checkbox, when entering the path into a text field, use a double slash prefix ( // ) to make it so. Relative paths are the default but this can be changed in the File tab of the User Preferences Editor.
A relative path is a way to specify the location of a directory relative to another directory. For example, suppose your documents are in C:\Sample\Documents and your index is in C:\Sample\Index. The absolute path for the documents would be C:\Sample\Documents.
This might be one solution to your problem: http://apidock.com/rails/ActionController/Base/prepend_view_path
I write a helper method to implement it. Sound like work perfectly.
def render_relative_partial(relative_path, option={})
caller_path = caller[0].split(".")[0].split("/")[0..-2].join("/")
path = caller_path.gsub("#{Rails.root.to_s}/app/views/","") + "/#{relative_path}"
option[:partial] = path
render option
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With