[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

RecordNotFound

Franz Bettag

3/16/2006 12:19:00 PM

Hi guys,

uhm how to fetch out a RecordNotFound?

i have this here

@new_ipv4 = Ipv4addr.find(IPAddr.new(params[:ipv4addr][:id]).to_i)

but at this line it gives an error RecordNotFound. But this is okay! But
now i want the application to do something special like adding the not
found IPaddr to the database.. But how? since it stops at this line =)

Thanks in advance!
--


Mit freundlichen Grüßen

Franz Bettag

____________________________
QS Housing
Franz Bettag
Ludwigstr. 45-47
90402 Nürnberg
http://www.qs-h...

Tel: +49 1805 737376 664
Fax: +49 1805 737376 665
4 Answers

Michael Gorsuch

3/16/2006 12:33:00 PM

0

Try using Ruby's exception handling:

begin
@new_ipv4 = Ipv4addr.find(IPAddr.new(params[:ipv4addr][:id]).to_i)
rescue
# Code to add data to database
end

A little more info:

http://www.rubycentral.com/book/tut_excep...

On 3/16/06, Franz Bettag <fbettag@qs-housing.net> wrote:
> Hi guys,
>
> uhm how to fetch out a RecordNotFound?
>
> i have this here
>
> @new_ipv4 = Ipv4addr.find(IPAddr.new(params[:ipv4addr][:id]).to_i)
>
> but at this line it gives an error RecordNotFound. But this is okay! But
> now i want the application to do something special like adding the not
> found IPaddr to the database.. But how? since it stops at this line =)
>
> Thanks in advance!
> --
>
>
> Mit freundlichen Grüßen
>
> Franz Bettag
>
> ____________________________
> QS Housing
> Franz Bettag
> Ludwigstr. 45-47
> 90402 Nürnberg
> http://www.qs-h...
>
> Tel: +49 1805 737376 664
> Fax: +49 1805 737376 665
>
>


Franz Bettag

3/16/2006 12:37:00 PM

0

Okay i got it myself. I did a .count before.. but that is quite unneeded
if you could check for RecordNotFound insted of just stopping there :)

Franz Bettag schrieb:
> Hi guys,
>
> uhm how to fetch out a RecordNotFound?
>
> i have this here
>
> @new_ipv4 = Ipv4addr.find(IPAddr.new(params[:ipv4addr][:id]).to_i)
>
> but at this line it gives an error RecordNotFound. But this is okay! But
> now i want the application to do something special like adding the not
> found IPaddr to the database.. But how? since it stops at this line =)
>
> Thanks in advance!


--


Mit freundlichen Grüßen

Franz Bettag

____________________________
QS Housing
Franz Bettag
Ludwigstr. 45-47
90402 Nürnberg
http://www.qs-h...

Tel: +49 1805 737376 664
Fax: +49 1805 737376 665

Franz Bettag

3/16/2006 12:37:00 PM

0

aaah! Thanks a lot!

Michael Gorsuch schrieb:
> Try using Ruby's exception handling:
>
> begin
> @new_ipv4 = Ipv4addr.find(IPAddr.new(params[:ipv4addr][:id]).to_i)
> rescue
> # Code to add data to database
> end
>
> A little more info:
>
> http://www.rubycentral.com/book/tut_excep...
>
> On 3/16/06, Franz Bettag <fbettag@qs-housing.net> wrote:
>
>>Hi guys,
>>
>>uhm how to fetch out a RecordNotFound?
>>
>>i have this here
>>
>>@new_ipv4 = Ipv4addr.find(IPAddr.new(params[:ipv4addr][:id]).to_i)
>>
>>but at this line it gives an error RecordNotFound. But this is okay! But
>>now i want the application to do something special like adding the not
>>found IPaddr to the database.. But how? since it stops at this line =)
>>
>>Thanks in advance!
>>--
>>
>>
>>Mit freundlichen Grüßen
>>
>>Franz Bettag
>>
>>____________________________
>>QS Housing
>>Franz Bettag
>>Ludwigstr. 45-47
>>90402 Nürnberg
>>http://www.qs-h...
>>
>>Tel: +49 1805 737376 664
>>Fax: +49 1805 737376 665
>>
>>
>
>


--


Mit freundlichen Grüßen

Franz Bettag

____________________________
QS Housing
Franz Bettag
Ludwigstr. 45-47
90402 Nürnberg
http://www.qs-h...

Tel: +49 1805 737376 664
Fax: +49 1805 737376 665

James Gray

3/16/2006 1:59:00 PM

0

On Mar 16, 2006, at 6:33 AM, Michael Gorsuch wrote:

> Try using Ruby's exception handling:
>
> begin
> @new_ipv4 = Ipv4addr.find(IPAddr.new(params[:ipv4addr][:id]).to_i)
> rescue

The above line would be better as:

rescue ActiveRecord::RecordNotFound

That way it doesn't hide errors we weren't expecting.

> # Code to add data to database
> end

James Edward Gray II