It’s a very basic question, i want just to test if this query did return
any result.
@BookDetails = Book.find(params[:id])
You will probably get better results asking this question on the Ruby
on Rails discussion forum. You have instead asked it on the ruby-talk
mailing list.
It’s a very basic question, i want just to test if this query did return
any result.
@BookDetails = Book.find(params[:id])
You will probably get better results asking this question on the Ruby
on Rails discussion forum. You have instead asked it on the ruby-talk
mailing list.
I actually think that this is an ActiveRecord question. Does this
qualify for a redirect to rails (even if params[:id] is a good hint)?
I have to admit that I do not know whether rails does change this
behaviour.
Do we cover ActiveRecord questions on ruby-talk?
To answer the original question:
ActiveRecord will raise an ActiveRecord::RecordNotFound exception which
you can detect/catch via
begin @BookDetails = Book.find(params[:id])
rescue ActiveRecord::RecordNotFound
the query did not return a result
end
Stefan
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.