Forum: Ruby on Rails RE: Application.rb 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.
unknown (Guest)
on 2006-01-13 01:05
(Received via mailing list)
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
Kevin O. (Guest)
on 2006-01-13 02:00
>
>    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
Spectre013 (Guest)
on 2006-01-13 02:30
(Received via mailing list)
On 1/12/06, removed_email_address@domain.invalid 
<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
This topic is locked and can not be replied to.