Rails equivalent of respond_to |format| with a straight render

Posted by brad on Stack Overflow See other posts from Stack Overflow or by brad
Published on 2010-04-29T17:57:16Z Indexed on 2010/04/29 18:17 UTC
Read the original article Hit count: 369

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?

© Stack Overflow or respective owner

Related posts about actioncontroller

Related posts about Xml