0
後空永諾我有兩個型號,Rails的外鍵是爲節省
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列。
在創建形式,我展示的過程可以使用select:
<%= 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總是空。我錯過了什麼?可能是顯而易見的,但我現在無法看到它。
謝謝!
嘗試都只是現在,同樣的結果,空數據庫。 –
你使用Rails 4嗎?你是否在'remark_params'中允許這個字段? – depa
是的,鐵軌4.但我不知道你對remark_params說什麼。 –