我有这些模型:
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
在 UsersController 我有这个:
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
奇怪的是,在编辑现有用户时,一切正常。知道这里出了什么问题吗?谢谢!