我有一些关系,有不同的模型子类型。
Class Venchile < ApplicationRecord; end
Class Car < Venchile; end
Class Moto < Venchile; end
@venchiles = Venchile.all
我有不同的部分:cars / _car.html.erb和motos / _moto.html.erb。然后我渲染整个集合
<%= render @venchiles %>
一切正常。每个模型都呈现自己的局部。但我有一个更具体的部分:cars / _car_info.html.erb和motos / _moto_info.html.erb
问题是如何使用不同的“* _info.html.erb”部分呈现整个混合集合@venchiles?
你应该问自己: “为什么来自同一型号的两个实例对象需要不同的视图?” 这可能是非正常关系的标志。它们可能属于不同的模型,或者至少它们具有不同的类型。