{"id":16948821,"url":"https://github.com/technicalpickles/safety_valve","last_synced_at":"2025-04-11T20:12:46.945Z","repository":{"id":440075,"uuid":"62009","full_name":"technicalpickles/safety_valve","owner":"technicalpickles","description":"Rails plugin to rescue common Rails exceptions, render an error with your look and feel, and return an appropriate HTTP status code","archived":false,"fork":false,"pushed_at":"2008-10-12T17:29:10.000Z","size":83,"stargazers_count":18,"open_issues_count":2,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-11T20:12:42.613Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/technicalpickles.png","metadata":{"files":{"readme":"README","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2008-10-12T01:21:57.000Z","updated_at":"2019-08-13T13:37:49.000Z","dependencies_parsed_at":"2022-07-04T16:30:28.254Z","dependency_job_id":null,"html_url":"https://github.com/technicalpickles/safety_valve","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/technicalpickles%2Fsafety_valve","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/technicalpickles%2Fsafety_valve/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/technicalpickles%2Fsafety_valve/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/technicalpickles%2Fsafety_valve/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/technicalpickles","download_url":"https://codeload.github.com/technicalpickles/safety_valve/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248473126,"owners_count":21109628,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T21:52:28.728Z","updated_at":"2025-04-11T20:12:46.918Z","avatar_url":"https://github.com/technicalpickles.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"SafetyValve\n===========\n\nBecause that pressure has to go somewhere.\n\nhttp://www.youtube.com/watch?v=7jF5r_AK9q4\u0026feature=related\n\nErrors 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?\n\nThat'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\n\nFor now, it only handles exceptions would be 404 (File Not Found) errors. This includes:\n\n * ActiveRecord::RecordNotFound\n * ActionController::RoutingError\n * ActionController::UnknownAction\n * ActionController::UnknownController\n\nExample\n=======\n\nUpdate your app/controller/application.rb to look something like:\n\n    class ApplicationController \u003c ActionController::Base\n      include SafetyValve::Controller\n      # ... rest of your code here\n    end\n    \nGenerate the error templates:\n\n    script/generate errors\n    \nThis 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:\n\n    \u003cdiv class=\"error\"\u003e\n      The resource you requested was not found.\n    \u003c/div\u003e\n    \n\nWe 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:\n\n    class EventsControllerTest \u003c Test::Rails::ControllerTestCase\n      context \"trying to view an event that doesn't exist\" do\n        setup do\n          get :show, :id =\u003e 'gibberish aieeeee'\n        end\n\n        should_respond_with :not_found # 404 works as well\n      end\n    end\n    \nThe effect\n==========\n\nIf 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.\n\nGotchas\n=======\n\nA few of the exceptions will always bubble up to the top in development mode, so you won't see the effect:\n\n * ActionController::RoutingError\n\nReferences\n==========\n\nThis plugin was inspired by some of these fine posts:\n\n * http://coderkitty.sweetperceptions.com/2008/7/6/meaningful-404s-and-500s\n * http://henrik.nyh.se/2008/07/rails-404\n * http://ryandaigle.com/articles/2007/9/24/what-s-new-in-edge-rails-better-exception-handling\n\nCopyright\n=========\n\nCopyright (c) 2008 Josh Nichols, released under the MIT license\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechnicalpickles%2Fsafety_valve","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftechnicalpickles%2Fsafety_valve","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechnicalpickles%2Fsafety_valve/lists"}