I have the following method, to throw a 404 if the request is made for xml,json or html.
def render_error(code, status_type = nil)
@error = ErrorMessage.new(code, status_type)
respond_to do |format|
format.any(:html, :json) { render @error.partial, status: @error.status }
format.any { render html: ErrorMessage.new(404).partial }
end
end
This is the partial method
def partial
'messages/show'
end
The same thing works if I use format.any { head 404, "content_type" => 'text/plain' }
instead of format.any { render html: ErrorMessage.new(404).partial }
.This is the error I get.
Missing template errors/index with {:locale=>[:en], :formats=>[:xml], :handlers=>[:erb, :builder, :raw, :ruby, :haml]}
when I request for test.xml
But I want to use stylized html error. What am I doing wrong here?