所以這是我的問題。我一直在和我在項目開始時創建的用戶合作一個月。今天筆者從sqllite切換到SQLSERVER,以滿足客戶的需求,我去的時候用我的註冊表單創建我有以下錯誤的新用戶:保存用戶時不能將符號轉換爲整數錯誤
can't convert Symbol into Integer
Parameters:
{"utf8"=>"✓",
"authenticity_token"=>"51nF50CYGNqz3N4o7TUYSyWeTadulXojQBPqERjvlcY=",
"user"=>{
"email"=>"[email protected]",
"login"=>"bgarrison",
"password"=>"[FILTERED]",
"password_confirmation"=>"[FILTERED]",
"profile_attributes"=>{
"prefix"=>"",
"first_name"=>"Bill",
"last_name"=>"Garrison",
"suffix"=>"",
"birthday"=>"1983-06-01",
"phone_numbers_attributes"=>{
"0"=>{
"info"=>"1234567890",
"label"=>"Cell"
}
}
}
},
"commit"=>"Register"}
我有一種感覺,在某些時候我搞砸了註冊過程,但我不能爲我的生活弄清楚在哪裏。用戶 - > has_one配置文件 - > has_many phone_numbers。
用戶控制器:
def create
@user = User.new(params[:user])
if @user.save
@profile = @user.profile
flash[:notice] = "Your account has been created."
redirect_to(@user)
else
flash[:notice] = "There was a problem creating you."
render :action => :new, :layout => 'logged_out'
end
end
用戶模型:
class User < ActiveRecord::Base
# Accessible attributes
attr_accessible :login,
:email,
:password,
:password_confirmation,
:profile_attributes,
:active
# Associations
has_one :profile, dependent: :destroy, autosave: true
# Allows for a profile hash in user creation (stored in :profile_attributes)
accepts_nested_attributes_for :profile
資料型號:
class Profile < ActiveRecord::Base
# Accessible Attributes
attr_accessible :birthday,
:company_id,
:first_name,
:last_name,
:prefix,
:suffix,
:phone_numbers_attributes,
:addresses_attributes
# Model Associations
has_many :phone_numbers, :as => :contactable, :class_name => "PhoneNumber", autosave: true
accepts_nested_attributes_for :phone_numbers, allow_destroy: true, reject_if: :all_blan
任何幫助,將不勝感激。謝謝!
更新:1另外,我還測試了一些,並意識到如果我離開了手機號碼,然後它工作.....如果我再更新使用相同的形式和添加電話號碼,一切工作正常。
可以包括在錯誤發生的代碼? – jvnill 2013-03-12 14:44:12
我沒有....其創建方法的第一行:@user = User.new(PARAMS [:用戶]) – 2013-03-12 14:45:52
噢我還忘了提及,我有:accepts_nested_attributes_for:PHONE_NUMBERS,allow_destroy:真,reject_if: :all_blank – 2013-03-12 14:47:05