我有两个模型医生和问题,如以下:
博士模型
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>
但这对我不起作用。你能给我一个合适的例子吗?