所以这是我的问题。一个月以来,我一直在与我在项目开始时创建的用户合作。今天我从sqllite切换到sqlserver以满足客户的要求,当我去使用我的注册表创建一个新用户时,我得到了以下错误:
can't convert Symbol into Integer
Parameters:
{"utf8"=>"✓",
"authenticity_token"=>"51nF50CYGNqz3N4o7TUYSyWeTadulXojQBPqERjvlcY=",
"user"=>{
"email"=>"test@blizzardlabs.com",
"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另外,我已经测试了一些,并意识到如果我遗漏了电话号码,那么它就可以工作......如果我然后使用相同的表格进行更新并添加一个电话号码,一切正常。