我有这些模型:
class User < ActiveRecord::Base
has_one :user_tms, :dependent => :destroy
accepts_nested_attributes_for :user_tms
end
class UserTms < ActiveRecord::Base
belongs_to :user
end
在“用户控制者”里,我有这个:
def new
@user = User.new
@user.build_user_tms
end
用户表看起来是这样的:
<%= form_for(@user) do |f| %>
<%= f.collection_select(:company_id, @companies, :id, :name, :include_blank => true) %>
<%= f.fields_for(:user_tms) do |tms_form| %>
<%= tms_form.collection_select(:department, @departments, :id, :description) %>
<% end %>
<% end %>
我认为很基本,但提交表格时,我得到错误:
User tms user can t be blank
奇怪的是,当编辑一个开放用户时,一切都很好。知道这里出了什么问题吗?谢谢!