I am developing an API for my application.
Here is the standard show method.
def show
@city = City.find(params[:id], :include => :state)
respond_to do |format|
format.html
format.xml
end
end
For a browser based action if the params[:id] is missing then ActiveRecord::RecordNotFound exception is raised which I let Rails handle. This results in public/404.html.
However in API I need to catch the exception and then I need to return an xml with the error message. What is the best way to handle that. Any example will be helpful
Right now even if I catch the exception then after catching the exception I need to process two different ways for html and xml. Secondly I need to know if I am processing html or xml. How do I find out if I am handing html or xml. Is there a utility method?
- Neeraj