This repository is private.
All pages are served over SSL and all pushing and pulling is done over SSH.
No one may fork, clone, or view it unless they are added as a member.
Every repository with this icon (
) is private.
Every repository with this icon (
This repository is public.
Anyone may fork, clone, or view it.
Every repository with this icon (
) is public.
Every repository with this icon (
commit ae33d19c5a460784f9ee6ffbc92b7ec6b159a775
tree 6f84cd5b3deb6e23318e9012a378e04307bec89b
parent 5b373704f0735845effaff4444bfb996296c9b6e
tree 6f84cd5b3deb6e23318e9012a378e04307bec89b
parent 5b373704f0735845effaff4444bfb996296c9b6e
| name | age | message | |
|---|---|---|---|
| |
MIT-LICENSE | Sat Oct 11 18:20:07 -0700 2008 | |
| |
README | Sat Oct 11 18:20:07 -0700 2008 | |
| |
Rakefile | Sun Oct 12 10:28:31 -0700 2008 | |
| |
generators/ | Sat Oct 11 18:20:07 -0700 2008 | |
| |
init.rb | Sat Oct 11 18:20:07 -0700 2008 | |
| |
lib/ | Sun Oct 12 10:28:31 -0700 2008 | |
| |
safety_valve.gemspec | Sun Oct 12 10:28:31 -0700 2008 | |
| |
tasks/ | Sat Oct 11 18:20:07 -0700 2008 | |
| |
test/ | Sat Oct 11 18:20:07 -0700 2008 |
README
SafetyValve =========== Because that pressure has to go somewhere. http://www.youtube.com/watch?v=7jF5r_AK9q4&feature=related Errors are bound to happen. When your users encounter one, by default, they will see a generic page provided by Rails. Wouldn't it be nice if you could give them an error page that fits the look and feel of your app? That's where comes in: it provides you with some sane defaults for rescuing from some common Rails exceptions. It also returns a HTTP status code that is appropriate For now, it only handles exceptions would be 404 (File Not Found) errors. This includes: * ActiveRecord::RecordNotFound * ActionController::RoutingError * ActionController::UnknownAction * ActionController::UnknownController Example ======= Update your app/controller/application.rb to look something like: class ApplicationController < ActionController::Base include SafetyValve::Controller # ... rest of your code here end Generate the error templates: script/generate errors This creates a template at app/views/errors/404.html.erb. It can be whatever you want, but here's what it looks like by default: <div class="error"> The resource you requested was not found. </div> We can now do functional tests that make sure we get 404 errors when accessing resources that don't exist. Here's an example in shoulda: class EventsControllerTest < Test::Rails::ControllerTestCase context "trying to view an event that doesn't exist" do setup do get :show, :id => 'gibberish aieeeee' end should_respond_with :not_found # 404 works as well end end The effect ========== If you're controller does a Model.find(params[:id]), and the record doesn't exist, you'll see ActiveRecord::RecordNotFound. SafetyValve will handle rescuing this, and will see that app/views/errors/404.html.erb (or 404.html.haml) is rendered. Gotchas ======= A few of the exceptions will always bubble up to the top in development mode, so you won't see the effect: * ActionController::RoutingError References ========== This plugin was inspired by some of these fine posts: * http://coderkitty.sweetperceptions.com/2008/7/6/meaningful-404s-and-500s * http://henrik.nyh.se/2008/07/rails-404 * http://ryandaigle.com/articles/2007/9/24/what-s-new-in-edge-rails-better-exception-handling Copyright ========= Copyright (c) 2008 Josh Nichols, released under the MIT license







