0

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?

user3438489
  • 309
  • 2
  • 5
  • 14

2 Answers2

0

I think you should do something like this:

    format.any { render :html => 'messages/show', object: ErrorMessage.new(404,nil) }
Papaya Labs
  • 1,079
  • 9
  • 11
0

Got it.. this worked format.any { render file: @error.partial, content_type: 'text/html', formats: [:html], status: @error.status }

user3438489
  • 309
  • 2
  • 5
  • 14