我有一个应用程序有subtasks
,subattributes
和weights
。Findind模型,属于两个模型与has_many通过协会
一个subtask
可以有很多通过weights
subattributes
,可以有很多weights
。
一个subattribute
可以有很多通过weights
subtasks
,可以有很多weights
。
A weight
可以同时属于subtask
和subattribute
。
现在我试图通过收集循环打印重量。但是,我在解决如何获得具体权重时遇到了问题。这是我有什么:
<% @subtasks.each do |subtask| %>
<% @subattributes.each do |subattribute| %>
<% if subattribute.subtasks.include (subtask) %>
#find the weight of that subattribute that's associated with that subtask
<% else %>
#create a new weight associated with the subattribute and subtask
<% end %>
<% end %>
<% end %>
任何建议。这是我的第一个rails应用程序,我没有设计后端,因为我个人会认为在子属性中只有一个字段会更容易。任何帮助将不胜感激。
试举你的问题更好的标题。此外,它还会帮助您添加模型的相关行。 – Meier