#280 √ invalid
David Smalley

Head method

Reported by David Smalley | April 23rd, 2008 @ 12:36 PM | in 0.9.4

It seems at the moment it is only possible to render an empty response by using a rather ugly render

render "", :layout => nil, :status => 404

It would be nice if there was a head method that could be called and passed an optional http status code to return responses without a body.

I was looking where to patch this in 0.9.2 but wasn't sure the best place for this method to sit. I will gladly make a patch for this if someone can point me to the best home for it.

Additionally, I did notice a reference to "render_nothing" in the new_render_api doc, but saw no other sign of it in merb-core.

Comments and changes to this ticket

  • Ben Burkert

    Ben Burkert April 24th, 2008 @ 06:40 AM

    try raising a NotFound, then in the not_found action of the exceptions controller, specify different provides. This way, you can have the json respond with a blank page, and the html present the error page.

  • David Smalley

    David Smalley April 24th, 2008 @ 10:06 AM

    I was thinking more how to issue a HEAD response (blank response body with headers useful for 404, 201 when dealing with xml etc.) than how to handle a 404 specifically.

  • Ben Burkert

    Ben Burkert April 24th, 2008 @ 10:23 AM

    route HEAD requests to a separate action that checks the resource. If it is ok, render_nothing. Otherwise, throw the exception for the status code. In the exception actions, check the request type. If it is HEAD, render_nothing. Otherwise, render the correct format.

  • David Smalley

    David Smalley April 24th, 2008 @ 10:31 AM

    Is render_nothing in Merb trunk because I can't seem to track it down in 0.9.2 and calling it in a controller doesn't seem to work.

    The only place I can find reference to it is in the new_render_api document in docs.

  • David Smalley

    David Smalley April 24th, 2008 @ 11:02 AM

    Also, I was thinking more of returning a HEAD response from Merb rather than dealing with an incoming HEAD request. Is that what you meant?

  • Michael Klishin (antares)

    Michael Klishin (antares) May 11th, 2008 @ 03:04 PM

    • → Milestone changed from “” to “0.9.4”
  • Michael D. Ivey (ivey)

    Michael D. Ivey (ivey) June 12th, 2008 @ 01:04 AM

    • → State changed from “new” to “invalid”

    Why are you using render() at all?

    def action_that_sets_status
      self.status = 401
      ""
    end
    

    If you do that a lot, you could wrap it in a helper.

    Rails needs render_nothing to prevent the auto-render from kicking in. Merb's render_nothing is

    return ""
    

    If someone still wants to pursue this, please feel free to work on a patch, but I don't think we need it.

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »