I''m recieving the error "You have a nil object when you didn''t expect it! The error occured while evaluating nil.each_hash", when trying to access a value from params. I''m trying to get the value with @c = @params[''CourseSection''][''section_name''] @params contains the following data {"commit"=>"Submit", "CourseSection"=>{"term"=>"fall", "course_subject"=>"cs", "section_number"=>"101", "course_number"=>"153"}} Any idea what I could be doing wrong. -Shaun -- Posted via http://www.ruby-forum.com/.
use @c = @params[''CourseSection''][''section_number''] instead -- Posted via http://www.ruby-forum.com/.
On 21 Nov 2005, at 21:39, shaun wrote:> @c = @params[''CourseSection''][''section_name''] > > {"commit"=>"Submit", "CourseSection"=>{"term"=>"fall", > "course_subject"=>"cs", "section_number"=>"101", > "course_number"=>"153"}} > > Any idea what I could be doing wrong.@params[''CourseSection''][''section_name''] is nil. You should set this, perhaps by having a form field in the previous view: <%= text_field "CourseSection", "section_name" %> Yours, Craig -- Craig Webster | t: +44 (0)131 516 8595 | e: craig-07VhxHapISisTnJN9+BGXg@public.gmane.org Xeriom.NET | f: +44 (0)709 287 1902 | w: http://xeriom.net
christer wrote:> use > > @c = @params[''CourseSection''][''section_number''] > > insteadSorry, misstyped it the first time arouund. I am using @c = @params[''CourseSection''][''section_number''] and recieving the error mentioned above. -- Posted via http://www.ruby-forum.com/.
craig wrote:> On 21 Nov 2005, at 21:39, shaun wrote: >> @c = @params[''CourseSection''][''section_name''] >> >> {"commit"=>"Submit", "CourseSection"=>{"term"=>"fall", >> "course_subject"=>"cs", "section_number"=>"101", >> "course_number"=>"153"}} >> >> Any idea what I could be doing wrong. > > @params[''CourseSection''][''section_name''] is nil. You should set this, > perhaps by having a form field in the previous view: <%= text_field > "CourseSection", "section_name" %> > > Yours, > Craig > -- > Craig Webster | t: +44 (0)131 516 8595 | e: craig-07VhxHapISisTnJN9+BGXg@public.gmane.org > Xeriom.NET | f: +44 (0)709 287 1902 | w: http://xeriom.netI don''t understand why @params[''CourseSection''][''section_number''] would be nil. CourseSection is a hash in a hash, so by asking for @params[''CourseSection''][''section_name''] should I not recieve the value for section_number, being "153" in this case. -- Posted via http://www.ruby-forum.com/.
shaun <sszot-e50bGt9CDiaVc3sceRu5cw@public.gmane.org> <sszot-e50bGt9CDiaVc3sceRu5cw@public.gmane.org> wrote:> craig wrote: >> On 21 Nov 2005, at 21:39, shaun wrote: >>> @c = @params[''CourseSection''][''section_name''] >>> >>> {"commit"=>"Submit", "CourseSection"=>{"term"=>"fall", >>> "course_subject"=>"cs", "section_number"=>"101", >>> "course_number"=>"153"}} >>> >>> Any idea what I could be doing wrong. >> >> @params[''CourseSection''][''section_name''] is nil. You should set this, >> perhaps by having a form field in the previous view: <%= text_field >> "CourseSection", "section_name" %> >> >> Yours, >> Craig >> -- >> Craig Webster | t: +44 (0)131 516 8595 | e: craig-07VhxHapISisTnJN9+BGXg@public.gmane.org >> Xeriom.NET | f: +44 (0)709 287 1902 | w: http://xeriom.net > > I don''t understand why @params[''CourseSection''][''section_number''] would > be nil. > CourseSection is a hash in a hash, so by asking for > @params[''CourseSection''][''section_name''] should I not recieve the value > for section_number, being "153" in this case.crap I can''t type today. section_name is actually section_number. I don''t understand why @params[''CourseSection''][''section_number''] would be nil. CourseSection is a hash in a hash, so by asking for @params[''CourseSection''][''section_number''] should I not recieve the value for section_number, being "153" in this case. -- Posted via http://www.ruby-forum.com/.
On 21 Nov 2005, at 22:01, shaun wrote:> I don''t understand why @params[''CourseSection''][''section_number''] > would > be nil. > CourseSection is a hash in a hash, so by asking for > @params[''CourseSection''][''section_name''] should I not recieve the > value > for section_number, being "153" in this case.Okay, let''s clarify: do you want the section_name or the section_number? Yours, Craig -- Craig Webster | t: +44 (0)131 516 8595 | e: craig-07VhxHapISisTnJN9+BGXg@public.gmane.org Xeriom.NET | f: +44 (0)709 287 1902 | w: http://xeriom.net
craig wrote:> On 21 Nov 2005, at 22:01, shaun wrote: >> I don''t understand why @params[''CourseSection''][''section_number''] >> would >> be nil. >> CourseSection is a hash in a hash, so by asking for >> @params[''CourseSection''][''section_name''] should I not recieve the >> value >> for section_number, being "153" in this case. > > Okay, let''s clarify: do you want the section_name or the section_number? > > Yours, > Craig > -- > Craig Webster | t: +44 (0)131 516 8595 | e: craig-07VhxHapISisTnJN9+BGXg@public.gmane.org > Xeriom.NET | f: +44 (0)709 287 1902 | w: http://xeriom.netsection_number is what I''m trying to get. Despite the fact that I keep typing it, section_name does not exist. -- Posted via http://www.ruby-forum.com/.
Sean, You must have something else wrong in your real code, because the code you''ve provided works just fine: irb(main):001:0> x = {"commit"=>"Submit", "CourseSection"=> {"term"=>"fall", irb(main):002:2* "course_subject"=>"cs", "section_number"=>"101", irb(main):003:2* "course_number"=>"153"}} => {"commit"=>"Submit", "CourseSection"=>{"course_subject"=>"cs", "term"=>"fall", "section_number"=>"101", "course_number"=>"153"}} irb(main):004:0> x["CourseSection"]["section_number"] => "101" Cheers, Pete Yandell