I am doing a query for some data, if the query is empty or returns no data because there is none. How do I show that the query was empty?
Here I am finding Todo’s via params[:id]
@todo = Todo.find(params[:id])
Now if this comes back with some data it will list out what is in the database. But if it returns nothing how do I show this?
if @todo == nil
@todo = "Sorry No Todo's!"
end
I have tried an if statement (above) but it does not work... How do I show the following text? “Sorry No Todo’s” if there is nothing in the database?

4 Comments
alexsuraci
Written Dec. 24, 2007 / Report /
Have you tried
if @todo.length == 0? I'm not sure if it's completely correct in this situation though.jrausell
Written Dec. 25, 2007 / Report /
you can try:
if (todo == "") todo = "Sorry No Todo's!"
if (todo == null) todo = "Sorry No Todo's!"
if (!todo) todo = "Sorry No Todo's!"
if (todo<=0) todo = "Sorry No Todo's!"
gregwinn
Written Dec. 26, 2007 / Report /
Hey, well here is what i ended up with.
if @todos.blank?flash[:notodo] = 'Sorry there are no todos.'
end
This is working as i needed, is there a better way to do this?
enc
Written Dec. 27, 2007 / Report /
@array.blank?is the best way to check if array is empty.