我有這些模型: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的日誌嗎? –