{"id":13879578,"url":"https://github.com/yuki24/rambulance","last_synced_at":"2025-05-14T06:11:25.323Z","repository":{"id":17523771,"uuid":"20311822","full_name":"yuki24/rambulance","owner":"yuki24","description":"Simple and safe way to dynamically render error pages or JSON responses for Rails apps","archived":false,"fork":false,"pushed_at":"2024-11-09T13:17:52.000Z","size":217,"stargazers_count":528,"open_issues_count":3,"forks_count":34,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-05-09T02:47:49.474Z","etag":null,"topics":["rails","rails-exceptions","ruby"],"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/yuki24.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-05-29T23:49:07.000Z","updated_at":"2025-05-01T13:35:26.000Z","dependencies_parsed_at":"2023-01-13T19:22:24.074Z","dependency_job_id":"9fda3be2-cc55-48a2-b361-35162b2128bb","html_url":"https://github.com/yuki24/rambulance","commit_stats":{"total_commits":236,"total_committers":16,"mean_commits":14.75,"dds":0.5084745762711864,"last_synced_commit":"986f0fb0a4d9037c61d5cc478f13a0ef3ca056a7"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuki24%2Frambulance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuki24%2Frambulance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuki24%2Frambulance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuki24%2Frambulance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yuki24","download_url":"https://codeload.github.com/yuki24/rambulance/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254079901,"owners_count":22011284,"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":["rails","rails-exceptions","ruby"],"created_at":"2024-08-06T08:02:25.784Z","updated_at":"2025-05-14T06:11:25.278Z","avatar_url":"https://github.com/yuki24.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# Rambulance [![build](https://github.com/yuki24/rambulance/actions/workflows/tests.yml/badge.svg)](https://github.com/yuki24/rambulance/actions/workflows/tests.yml) [![Gem Version](https://badge.fury.io/rb/rambulance.svg)](https://rubygems.org/gems/rambulance)\n\nA simple and safe way to dynamically render error pages for Rails apps.\n\n## Features\n\n### Simple and Safe\n\nRambulance's exceptions app is simple, skinny and well-tested. It  inherits from `ActionController::Base`, so it works fine even if your `ApplicationController` has an issue.\n\n### Flexible\n\nYou have full control of which error page to show for a specific exception. It also json rendering (perfect for API apps). It even provides a way to create a custom exceptions app.\n\n### Easy installation and development\n\nYou don't have to configure things that every single person has to do and Rambulance does everything for you.\n\n## Installation and Usage\n\nAdd this line to your application's Gemfile:\n\n```\ngem 'rambulance'\n```\n\nAnd then execute:\n\n```\n$ rails g rambulance:install\n```\n\nRambulance's generator can only generate `erb` templates. If you want to use haml or slim templates, please see [How to Convert Your `.erb` to `.slim`](https://github.com/slim-template/slim/wiki/Template-Converters-ERB-to-SLIM) or [html2haml](https://github.com/haml/html2haml).\n\nNow you can start editing templates like `app/views/errors/not_found.html.erb`. Edit, run `rails server` and open [`localhost:3000/rambulance/not_found`](http://localhost:3000/rambulance/not_found)!\n\n## Setting Pairs of Exceptions and HTTP Statuses\n\nOpen `config/initializers/rambulance.rb` and to configure the list of pairs of exception/corresponding http status.\nFor example, if you want to display:\n\n * 422(unprocessable entity) for `ActiveRecord::RecordNotUnique`\n * 403(forbidden) for `CanCan::AccessDenied`\n * 404(not found) for `YourCustomException`\n\nThen do the following:\n\n```ruby\n# config/initializers/rambulance.rb\nconfig.rescue_responses = {\n  \"ActiveRecord::RecordNotUnique\" =\u003e :unprocessable_content,\n  \"CanCan::AccessDenied\"          =\u003e :forbidden,\n  \"YourCustomException\"           =\u003e :not_found\n}\n```\n\n## Special case `unprocessable_entity`/`unprocessable_content` (HTTP Status 422)\n\nRack renamed `unprocessable_entity` to `unprocessable_content`.\n\nRambulance supports both, but defaults to `unprocessable_content` with version 3.2.0 and later.\n`unprocessable_entity` is supported with a redirect to `unprocessable_content`.\n\nThis means the view file is called `app/views/errors/unprocessable_content.html.erb`, not `app/views/errors/unprocessable_entity.html.erb`.\n\n## Local Development\n\n### Open `localhost:3000/rambulance/***` in Your Browser\n\nJust open one of the error pages via Rambulance:\n\n * [`localhost:3000/rambulance/not_found`](http://localhost:3000/rambulance/not_found) or\n * [`localhost:3000/rambulance/internal_server_error`](http://localhost:3000/rambulance/internal_server_error)\n\nThis is useful when you want to edit templates without changing Rails configuration.\n\n### Set `consider_all_requests_local` to _false_\n\nChange `config.consider_all_requests_local` to _false_ in `config/environments/development.rb`.\n\n```ruby\nconfig.consider_all_requests_local = false\n```\n\nThis simulates how your production app displays error pages so you can actually raise an exception in your app and see how it works. Don't forget to change `consider_all_requests_local` back to _true_ after you tried this strategy.\n\n## Custom Exceptions App\n\nIf you want to do some more things in a exceptions app, you can also write your own custom exceptions app:\n\n```sh\n$ rails g rambulance:exceptions_app\n```\n\nIt will generate your own custom exceptions app. You can use most techniques you want to use in controllers like `before_filter` and rendering views since it's a grandchild of `ActionController::Base`! However there are still some restrictions, e.g. setting a flash notice works when rendering directly but not when redirecting because the ActionDispatch::Flash middleware is never hit.\n\n**Heavily customizing the exceptions app is strongly discouraged as there would be no guard against bugs that occur in the exceptions app.**\n\n## Testing\n\nRambulance ships with a test helper that allows you to test an error page generated by Rails. All you have to do is to `include Rambulance::TestHelper` and you will be able to use the `with_exceptions_app` DSDL:\n\nRspec:\n\n```ruby\ninclude Rambulance::TestHelper\n\nit \"shows an error page\" do\n  with_exceptions_app do\n    get '/does_not_exist'\n  end\n\n  assert_equal 404, response.status\nend\n```\n\nMinitest:\n\n```ruby\ninclude Rambulance::TestHelper\n\ntest \"it shows an error page\" do\n  with_exceptions_app do\n    get '/does_not_exist'\n  end\n\n  assert_equal 404, response.status\nend\n```\n\nNote that testing error pages is not encouraged in Rails as it leads to overuse of the `rescue_from` DSL in controllers.\n\n## Supported Versions\n\n* Ruby 2.5, 2.6, 2.7, 3.0, 3.1, 3.2, 3.3 and JRuby 9.3, 9.4\n* Rails 4.2, 5.0, 5.1, 5.2, 6.0, 6.1, 7.0, 7.1 and edge\n\nRambulance doesn't work with Rails 3.1 and below since they don't provide a way to use a custom exceptions app.\n\n## Contributing\n\n1. Fork it ( https://github.com/yuki24/rambulance/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## License\n\nCopyright (c) 2014-2015 Yuki Nishijima. See LICENSE.txt for further details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuki24%2Frambulance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyuki24%2Frambulance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuki24%2Frambulance/lists"}