我有这些模型:HAS_ONE关系不工作的新/创建
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
而奇怪的是,当编辑一个现有的用户,一切工作正常。任何想法在这里出了什么问题?谢谢!
你可以显示请求和SQL的日志吗? –