Forum: Ruby on Rails Problem with RecordNotFound without numeric id

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.
Tommaso P. (Guest)
on 2006-01-09 20:02
(Received via mailing list)
Hi all,

I have a problem handling errors for RecordNotFound (Page 86 of Agile
Book), I want to redirect bad items id to "list" with a flash "Invalid
Item", but this works only with numeric id, if I use some like
"wibble" the result is an empty list of items.

This is in my item_controller:

def show
  @item = Item.find(params[:id])
  rescue
  redirect_to :action => 'list'
  flash[:notice] = 'Invalid Item'
end
Jules J. (Guest)
on 2006-01-09 20:06
@item = Item.find(params[:id].to_i)
This topic is locked and can not be replied to.