#44 ✓resolved
Matt Todd

Extensive Responses without Exceptions

Reported by Matt Todd | June 26th, 2008 @ 08:58 AM | in Release 0.5.1

Currently, the easiest way to respond with anything other than a 200 OK response or a 404 Not Found response is to throw an exception. This is trivial, but it of course causes problems with flow control and isn't exactly the best API.

A better option would to provide some sort of lookup method similar to ok but including a symbolic version of the HTTP errors as well. (This will require some additional information included with the exceptions.rb file, but that is a trivial change.)

Here is an example:

class Foos < Application
  def create
    @foo = Foo.new
    # pre-save logic here
    if @foo.save
      status :created
    else
      error :unprocessable_entity
    end
  end
end

Of course, other method names may be better, but these were the first two I came up with. Technically, error and status could be aliases.

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

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

People watching this ticket

Pages