me gustaría tener la siguiente estructura de directorios:¿Cómo puedo agregar una ruta de vista a la búsqueda de representación parcial de Rails?
views/
app1/
users/_user.html.erb
users/index.html.erb
app2/
users/index.html.erb
shared/
users/_user.html.erb
users/index.html.erb
En mi opinión, me gustaría llamar
# app1/users/index.html
<%= render :partial => "user" %>
# => /app1/users/_user.html.erb
# app2/users/index.html
<%= render :partial => "user" %>
# => /shared/users/_user.html.erb
Así que, básicamente, ¿cómo le digo rieles para comprobar en el/app2/¿Los usuarios dirán luego el directorio compartido antes de que aparezca su error de plantilla faltante?
actualización
llegué alrededor de este (según lo sugerido por Senthil, utilizando File.exist?
aquí está mi solución - comentarios y sugerencias bienvenidos
# application_helper.rb
# Checks for a partial in views/[vertical] before checking in views/shared
def partial_or_default(path_name, options={}, &block)
path_components = path_name.split("/")
file_name = path_components.pop
vertical_file_path = File.join(vertical}, path_components, file_name)
shared_file_path = File.join("shared", path_components, file_name)
full_vertical_file_path = File.join("#{Rails.root}/app/views/", "_#{vertical_file_path}.html.erb")
attempt_file_path = File.exist?(full_vertical_file_path) ? vertical_file_path : shared_file_path
render({:partial => attempt_file_path}.merge(options), &block)
end
¿Por qué no puede usar 'File.exists?' Para verificar si el archivo sale y muestra el archivo apropiado? –