0
一對多的關係,我有兩個型號,醫生和像follwong問題:ROR accepts_nested_attributes_for一個與選擇
醫生型號
class Doctor < ActiveRecord::Base
has_many :questions
has_many :brands
accepts_nested_attributes_for :questions
end
問題模型
class Question < ActiveRecord::Base
belongs_to :discipline
belongs_to :doctor
belongs_to :brand
end
現在你可以清楚地看到,醫生有很多問題和品牌,問題屬於醫生和品牌。我想從醫生編輯頁面上添加以前保存的問題給醫生。 我也想刪除它們。我該如何處理?
我想這樣的:
<%= form.fields_for :questions, question,:child_index => (question.new_record? ? "index_to_replace_with_js" : nil) do |question_form| %>
<table>
<tr>
<td>
<div class="label">Select Question</div>
<%= question_form.collection_select :id, Question.all, :id, :title ,{:include_blank => true } %>
</td>
</tr>
</table>
但是這亙古不變的me.Can你給我適當例如解決方案的工作?
我已經看過這個。請查看「我想從醫生編輯頁面向醫生添加先前保存的問題」一行。我該怎麼做呢?具體來說,這是我的問題。 – 2012-04-14 05:44:33