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.
D105b980e30e1b77fc761b1cd1b2de32?d=identicon&s=25 unknown (Guest)
on 2006-01-13 00: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
C8a634a01a2c4508360874bff7fb1a7f?d=identicon&s=25 Kevin Olbrich (olbrich)
on 2006-01-13 01: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
Daf46a55e32d22921891cf83c5d872b9?d=identicon&s=25 Spectre013 (Guest)
on 2006-01-13 01:30
(Received via mailing list)
On 1/12/06, Matt.C.Wagner@wellsfargo.com <Matt.C.Wagner@wellsfargo.com>
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.