Question

I'm working with ActiveResource a lot so my service models are only using XML. Thus, I have no need for a respond_to block, I literally just render :xml => @model

I can't however figure out how to render a 404 header using this. I've had to resort to respond_to, which I think adds a few unnecessary method calls. Here's what I'm using:

respond_to do |format|
  if (record_found)
    render :xml => @some_record
  else
    format.xml{ head :not_found }
  end
end

but I just want something like render :xml => head :not_found which doesn't work. Can anyone tell me the proper syntax?

Was it helpful?

Solution

Have you tried:

render {:xml => "Record not found", :status => :not_found }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top