# Retrieving value from @params

**URL:** <https://www.ruby-forum.com/t/retrieving-value-from-params/48525>\
**Category:** Rails\
**Created:** [November 21, 2005, 10:39pm UTC](https://www.ruby-forum.com/t/retrieving-value-from-params/48525 "2005-11-21T22:39:14Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![shaun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f07891/32.png) [@shaun](https://www.ruby-forum.com/u/shaun)\
**Post date:** [November 21, 2005, 10:39pm UTC](https://www.ruby-forum.com/t/retrieving-value-from-params/48525/1 "2005-11-21T22:39:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![shaun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f07891/32.png) [@shaun](https://www.ruby-forum.com/u/shaun)\
**Post date:** [November 21, 2005, 10:45pm UTC](https://www.ruby-forum.com/t/retrieving-value-from-params/48525/2 "2005-11-21T22:45:43Z")

</div>

use

@c = @params[‘CourseSection’][‘section\_number’]

instead

---

<div class="post-metadata">

**Author:** ![shaun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f07891/32.png) [@shaun](https://www.ruby-forum.com/u/shaun)\
**Post date:** [November 21, 2005, 10:49pm UTC](https://www.ruby-forum.com/t/retrieving-value-from-params/48525/3 "2005-11-21T22:49:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![shaun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f07891/32.png) [@shaun](https://www.ruby-forum.com/u/shaun)\
**Post date:** [November 21, 2005, 10:51pm UTC](https://www.ruby-forum.com/t/retrieving-value-from-params/48525/4 "2005-11-21T22:51:32Z")

</div>

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 W. | t: +44 (0)131 516 8595 | e: removed\_email\_address@domain.invalid  
[Xeriom.NET](http://Xeriom.NET) | f: +44 (0)709 287 1902 | w: [http://xeriom.net](http://xeriom.net)

---

<div class="post-metadata">

**Author:** ![shaun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f07891/32.png) [@shaun](https://www.ruby-forum.com/u/shaun)\
**Post date:** [November 21, 2005, 11:01pm UTC](https://www.ruby-forum.com/t/retrieving-value-from-params/48525/5 "2005-11-21T23:01:16Z")

</div>

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 W. | t: +44 (0)131 516 8595 | e: removed\_email\_address@domain.invalid  
> [Xeriom.NET](http://Xeriom.NET) | f: +44 (0)709 287 1902 | w: [http://xeriom.net](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.

---

<div class="post-metadata">

**Author:** ![shaun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f07891/32.png) [@shaun](https://www.ruby-forum.com/u/shaun)\
**Post date:** [November 21, 2005, 11:07pm UTC](https://www.ruby-forum.com/t/retrieving-value-from-params/48525/6 "2005-11-21T23:07:38Z")

</div>

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 W. | t: +44 (0)131 516 8595 | e: removed\_email\_address@domain.invalid  
[Xeriom.NET](http://Xeriom.NET) | f: +44 (0)709 287 1902 | w: [http://xeriom.net](http://xeriom.net)

---

<div class="post-metadata">

**Author:** ![shaun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f07891/32.png) [@shaun](https://www.ruby-forum.com/u/shaun)\
**Post date:** [November 21, 2005, 11:12pm UTC](https://www.ruby-forum.com/t/retrieving-value-from-params/48525/7 "2005-11-21T23:12:00Z")

</div>

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 W. | t: +44 (0)131 516 8595 | e: removed\_email\_address@domain.invalid  
> [Xeriom.NET](http://Xeriom.NET) | f: +44 (0)709 287 1902 | w: [http://xeriom.net](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.

---

<div class="post-metadata">

**Author:** ![shaun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f07891/32.png) [@shaun](https://www.ruby-forum.com/u/shaun)\
**Post date:** [November 22, 2005, 4:37am UTC](https://www.ruby-forum.com/t/retrieving-value-from-params/48525/8 "2005-11-22T04:37:22Z")

</div>

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 Y.

---

<div class="post-metadata">

**Author:** ![shaun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f07891/32.png) [@shaun](https://www.ruby-forum.com/u/shaun)\
**Post date:** [November 21, 2005, 11:03pm UTC](https://www.ruby-forum.com/t/retrieving-value-from-params/48525/9 "2005-11-21T23:03:15Z")

</div>

shaun [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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 W. | t: +44 (0)131 516 8595 | e: removed\_email\_address@domain.invalid  
> > [Xeriom.NET](http://Xeriom.NET) | f: +44 (0)709 287 1902 | w: [http://xeriom.net](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.
