これが私の問題です。プロジェクトの開始時に作成したユーザーと1か月間協力しています。今日、クライアントの要件を満たすために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_manyphone_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また、いくつかのテストを行い、電話番号を省略しても機能することを確認しました。同じフォームを使用して更新し、電話番号を追加すると、すべて正常に機能します。