Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to render XML error messages separately in Ruby on Rails?

I'm creating a simple XML API in Rails, and currently, when there's an error, it renders the standard HTML error pages in public/, e.g. error in /tests.xml causes rendering of public/404.html.

Is there a way to make it render public/404.xml instead?

like image 606
Ian morgan Avatar asked Jul 29 '10 11:07

Ian morgan


1 Answers

You probably want to take advantage of the fact that the render method can render custom XML and an HTTP status, like so:

# Renders '<error>Not found</error>'
render :xml => { :error => 'Not found' }, :status => 404
like image 172
John Topley Avatar answered Oct 16 '22 12:10

John Topley