我有两个模型,
class ProcessType < ActiveRecord::Base
has_many :remarks
validates :code, :name, presence: true
end
class Remark < ActiveRecord::Base
belongs_to :process_type
belongs_to :origin
validates :description, presence: true
end
外键设置正确,备注表中有一个process_type_id列。
在“创建”表单上,我使用选择显示可用的过程:
<%= simple_form_for @remark do |f| %>
<%= collection_select(:remark, :process_type_id, ProcessType.all, :id, :name) %>
<%= f.input :description, label: 'Description' %>
<%= f.input :suggestion, label: 'Suggestion' %>
<%= f.button :submit %>
<% end %>
我的问题是在备注表中,保存后,进程的ID始终为null。我想念什么?可能很明显,但是我现在看不到它。
谢谢!
试试这个:
<%= f.collection_select :process_type_id, ProcessType.all, :id, :name %>
或者,如果您想使用简单表单方法:
<%= f.input :process_type_id, :collection => ProcessType.all %>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句