次のディレクトリ構造が必要です。
views/
app1/
users/_user.html.erb
users/index.html.erb
app2/
users/index.html.erb
shared/
users/_user.html.erb
users/index.html.erb
私の見解では、私は電話します
# app1/users/index.html
<%= render :partial => "user" %>
# => /app1/users/_user.html.erb
# app2/users/index.html
<%= render :partial => "user" %>
# => /shared/users/_user.html.erb
基本的に、Railsに/ app2 / usersディレクトリをチェックインしてから共有ディレクトリをチェックインしてから、テンプレートが見つからないというエラーが発生するように指示するにはどうすればよいですか?
アップデート
私はこれを回避しました(Senthilによって提案されたように、File.exist?
これが私の解決策です-フィードバックと提案を歓迎します
# 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