私はネストされたハッシュで遊んでいます。タスク:TypeErrorを取得するのはなぜですか:シンボルをIntegerに暗黙的に変換しませんか?
Create three hashes called
person1
,person2
, andperson3
, with first and last names under the keys:first
and:last
. Then create a params hash so thatparams[:father]
isperson1
,params[:mother]
isperson2
, andparams[:child]
isperson3
. Verify that, for example,params[:father][:first]
has the right value.
私のソリューション:その後、
person1 = {first: "first_name1", last: "last_name1"}
person2 = {first: "first_name2", last: "last_name2"}
person3 = {first: "first_name3", last: "last_name3"}
params = { :father => ":person1", :mother => ":person2", :child => ":person3" }
params[:father][:first]
は
TypeError: no implicit conversion of symbol into Integer
なぜを与えますか?私はなぜTypeErrorを取得するのか分からない。
パラメータをアクセスキーと値のペアのparams = {:父=> "person1"、:mother => ":person2"、:child => "person3"}とアクセスするparams [:father]結果 "person1" –
これは分かります。私は混乱していた複数の議論を通過していました。 – Savina10