# RE: Application.rb params\[\]

**URL:** <https://www.ruby-forum.com/t/re-application-rb-params/95109>\
**Category:** Rails\
**Created:** [January 13, 2006, 12:05am UTC](https://www.ruby-forum.com/t/re-application-rb-params/95109 "2006-01-13T00:05:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 13, 2006, 12:05am UTC](https://www.ruby-forum.com/t/re-application-rb-params/95109/1 "2006-01-13T00:05:41Z")

</div>

Spectre013 wrote:

> Here is the line
> 
> if params[:day]

Spectre013,

I was having a similar problem testing for the existence of a param[] in  
my controller. I solved it like this:

if !defined? params[:id] || params[:id].nil  
redirect\_to :action =\> ‘list’  
else  
@foobar = FooBar.find(params[:id])  
end

Maybe this helps.

Matt

–  
Matt C. Wagner  
Information Security Analyst

Network Intrusion Detection  
Security Operations Center  
Corporate Information Security  
Wells Fargo Bank

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 13, 2006, 1:00am UTC](https://www.ruby-forum.com/t/re-application-rb-params/95109/2 "2006-01-13T01:00:09Z")

</div>

> if !defined? params[:id] || params[:id].nil  
> redirect\_to :action =\> ‘list’  
> else  
> @foobar = FooBar.find(params[:id])  
> end

This might also work…

…  
redirect\_to :action =\> ‘list’ unless params[:id]  
@foobar = FooBar.find(params[:id])  
…

\_Kevin

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [January 13, 2006, 1:30am UTC](https://www.ruby-forum.com/t/re-application-rb-params/95109/3 "2006-01-13T01:30:22Z")

</div>

On 1/12/06, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> if !defined? params[:id] || params[:id].nil  
> redirect\_to :action =\> ‘list’  
> else  
> @foobar = FooBar.find(params[:id])  
> end
> 
> Maybe this helps.
> 
> Matt

Still throws a nil error when called in the initialize method, thanks  
for  
the example will keep it in mind as I learn Rails.

Brian
