Rails3 の記述方法を教えてください。
{"utf8"=>"✓",
"authenticity_token"=>"bqoR9tW+GGskvv4MRTtd1OikjwPKLeACkl7S/Pv55jE=",
"studylogheader"=>{"studydate"=>"2011-06-07",
"member_id"=>"902806575",
"comment_member"=>"頑張ったけど、だめだった。もうしんどい。",
"comment_staff"=>"comment_staff01",
"comment_parent"=>"comment_parent01"},
"studylogdetails"=>[{"starttime"=>{"(1i)"=>"2011",
"(2i)"=>"6",
"(3i)"=>"17",
"(4i)"=>"11",
"(5i)"=>"00"},
"endtime"=>{"(1i)"=>"2011",
"(2i)"=>"6",
"(3i)"=>"17",
"(4i)"=>"12",
"(5i)"=>"00"},
"place"=>"totto",
"studycontent"=>"aaaaa"},
{"place"=>"totto",
"studycontent"=>"aaaaa",
"starttime"=>{"(1i)"=>"2011",
"(2i)"=>"6",
"(3i)"=>"17",
"(4i)"=>"12",
"(5i)"=>"00"},
"endtime"=>{"(1i)"=>"2011",
"(2i)"=>"6",
"(3i)"=>"17",
"(4i)"=>"13",
"(5i)"=>"00"}},
{"place"=>"totto",
"studycontent"=>"aaaaa",
"starttime"=>{"(1i)"=>"2011",
"(2i)"=>"6",
"(3i)"=>"17",
"(4i)"=>"07",
"(5i)"=>"47"},
"endtime"=>{"(1i)"=>"2011",
"(2i)"=>"6",
"(3i)"=>"17",
"(4i)"=>"07",
"(5i)"=>"47"}},
{"place"=>"totto",
"studycontent"=>"aaaaa",
"starttime"=>{"(1i)"=>"2011",
"(2i)"=>"6",
"(3i)"=>"17",
"(4i)"=>"07",
"(5i)"=>"47"},
"endtime"=>{"(1i)"=>"2011",
"(2i)"=>"6",
"(3i)"=>"17",
"(4i)"=>"07",
"(5i)"=>"47"}},
{"place"=>"totto",
"studycontent"=>"aaaaa",
"starttime"=>{"(1i)"=>"2011",
"(2i)"=>"6",
"(3i)"=>"17",
"(4i)"=>"07",
"(5i)"=>"47"},
"endtime"=>{"(1i)"=>"2011",
"(2i)"=>"6",
"(3i)"=>"17",
"(4i)"=>"07",
"(5i)"=>"47"}},
{"place"=>"totto",
"studycontent"=>"aaaaa"}],
"commit"=>"Save changes"}
上記のような params です。
01: index = 0
02: params[:studylogdetails].map { |hash|
03: studylogdetails[index].starttime =
04: Time.new(
05: hash[:starttime]["(1i)"].to_i,
06: hash[:starttime]["(2i)"].to_i,
07: hash[:starttime]["(3i)"].to_i,
08: hash[:starttime]["(4i)"].to_i,
09: hash[:starttime]["(5i)"].to_i, 0)
10: ......<中略>
11: studylogdetails[index].save
12: index = index + 1
13: }
このようなコードで、行05 で以下のようなエラーになります。
You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]
どなたかわかる方、お願いします。
お礼
うまくゆきました。ありがとうございました!