subtasks
,subattributes
、およびweights
のアプリケーションがあります。アソシエーションを介してhas_manyを持つ2つのモデルに属しているFindindモデル
subtask
はweights
を通じて多くのsubattributes
を持つことができ、weights
多くを持つことができます。
subattribute
はweights
を通じて多くのsubtasks
を持つことができ、weights
多くを持つことができます。
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 %>
何か提案があります。これは私の最初のレールアプリであり、私は個人的には重量をサブ属性のフィールドにする方が簡単だと思っていたので、バックエンドを設計していませんでした。どんな助けでも大歓迎です。
は、あなたの質問に、より良いタイトルを与えることを試みます。また、それはあなたのモデルの関連ラインを追加するのに役立ちます。 – Meier