Forum: Ruby on Rails retrieving value from @params

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
811a7ce34dba822b542ca2fe916b913f?d=identicon&s=25 shaun (Guest)
on 2005-11-21 22:39
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
Af95bdaf87958c40150b813e94381bfd?d=identicon&s=25 Christer Nilsson (christer)
on 2005-11-21 22:45
use

@c = @params['CourseSection']['section_number']

instead
811a7ce34dba822b542ca2fe916b913f?d=identicon&s=25 shaun <sszot@mscs.mu.edu> (Guest)
on 2005-11-21 22:49
christer wrote:
> use
>
> @c = @params['CourseSection']['section_number']
>
> instead

Sorry, misstyped it the first time arouund. I am using
@c = @params['CourseSection']['section_number'] and recieving the error
mentioned above.
5cfd7e9223637ea26c81c2cc3e43799e?d=identicon&s=25 craig (Guest)
on 2005-11-21 22:51
(Received via mailing list)
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@xeriom.net
Xeriom.NET    | f: +44 (0)709 287 1902 | w: http://xeriom.net
811a7ce34dba822b542ca2fe916b913f?d=identicon&s=25 shaun <sszot@mscs.mu.edu> <sszot@mscs.mu.edu> (Guest)
on 2005-11-21 23:01
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@xeriom.net
> 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.
811a7ce34dba822b542ca2fe916b913f?d=identicon&s=25 shaun <sszot@mscs.mu.edu> <sszot@mscs.mu.edu> <ssz (Guest)
on 2005-11-21 23:03
shaun <sszot@mscs.mu.edu> <sszot@mscs.mu.edu> 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@xeriom.net
>> 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.
5cfd7e9223637ea26c81c2cc3e43799e?d=identicon&s=25 craig (Guest)
on 2005-11-21 23:07
(Received via mailing list)
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@xeriom.net
Xeriom.NET    | f: +44 (0)709 287 1902 | w: http://xeriom.net
811a7ce34dba822b542ca2fe916b913f?d=identicon&s=25 shaun <sszot@mscs.mu.edu> <sszot@mscs.mu.edu> <ssz (Guest)
on 2005-11-21 23:12
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@xeriom.net
> Xeriom.NET    | f: +44 (0)709 287 1902 | w: http://xeriom.net

section_number is what I'm trying to get. Despite the fact that I keep
typing it, section_name does not exist.
C9c7a65848f13e2b1a226bbe43bc3672?d=identicon&s=25 Pete Yandell (pete)
on 2005-11-22 04:37
(Received via mailing list)
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
This topic is locked and can not be replied to.