Ruby on rails ROR为与选择的一对多关系接受_嵌套的_属性
我有两个模型,医生和问题如下: 博士模型Ruby on rails ROR为与选择的一对多关系接受_嵌套的_属性,ruby-on-rails,ruby-on-rails-3,nested-attributes,Ruby On Rails,Ruby On Rails 3,Nested Attributes,我有两个模型,医生和问题如下: 博士模型 class Doctor < ActiveRecord::Base has_many :questions has_many :brands accepts_nested_attributes_for :questions end classdoctor 但是这对我不起作用。你能给我一个合适的例子来解决吗?它看起来像 和 回答得好。我已经看过了。请看“我想从医生编辑页面向医生添加以前保存的问题”一行。我该怎么做?这是我的问题。
class Doctor < ActiveRecord::Base
has_many :questions
has_many :brands
accepts_nested_attributes_for :questions
end
classdoctor
问题模型
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>
(question.new_record??“index_to_replace_with_js”:nil)do | question_form |%>
选择问题
真}%>
但是这对我不起作用。你能给我一个合适的例子来解决吗?它看起来像和
回答得好。我已经看过了。请看“我想从医生编辑页面向医生添加以前保存的问题”一行。我该怎么做?这是我的问题。