I'm new to rails and am learning my way by putting together a simple
app.
I'm pulling items out of the params by using find(params['id']) and
showing results in a show view.
Things are going along nicely until I enter an ID into the address bar
that does not exist. Then the whole thing blows up and I get ACTIVE
RECORD::RECORD NOT FOUND IN PUBLIC CONTROLLER#SHOW along with
"couldn't find item with ID = 100" .
I'm new to rails and am learning my way by putting together a simple
app.
I'm pulling items out of the params by using find(params['id']) and
showing results in a show view.
Things are going along nicely until I enter an ID into the address bar
that does not exist. Then the whole thing blows up and I get ACTIVE
RECORD::RECORD NOT FOUND IN PUBLIC CONTROLLER#SHOW along with
"couldn't find item with ID = 100" .
That's what find does. It's up to you to rescue
ActiveRecord::RecordNotFound and do something different
So I would like to have a 'No record found' displayed when non
existant ID is inserted just like find_by_id does when it returns nil.
This would be something like:
def show
@album = Album.find_by_id(params[:id])
unless @album then
# Here you could render a template or redirect to a different action
render :template => 'record_not_found'
end
# When the album is found, the default template for this method is
rendered
end