Got an error on returning data as json format when the data is nil

Hi there,

One of my app's actions returns data as a json format.
If the data exists, everything works perfect.
But if the data is nil, I get the following error.

wolfgang wrote:

How can I avoid this situation ???

I don't know specifically why Rails generates that particular error, but
that doesn't really matter, because render :json => nil is not valid.
You need to check for nil and respond with a properly constructed error
response, including the proper HTTP error status. I think most people
response with a 404 - Page not found in this case, but I'm not
completely sure of that.

Hi Robert,

Thanks for reply.

So does it mean JSON cannot represent a single nil object ? serious !?

Ajax calls the action and it can treat the error as nil object as you mentioned
but isn't it ugly ???

thanks in advance.

wolfgang