All Projects → yuki24 → Rambulance

yuki24 / Rambulance

Licence: mit
Simple and safe way to dynamically render error pages or JSON responses for Rails apps

Programming Languages

ruby
36898 projects - #4 most used programming language

Labels

Projects that are alternatives of or similar to Rambulance

Learn Rails
An example Rails 5.1 app to accompany the "Learn Ruby on Rails" book.
Stars: ✭ 375 (-11.35%)
Mutual labels:  rails
Doctor
Doctor is a documentation server for your docs in github
Stars: ✭ 391 (-7.57%)
Mutual labels:  rails
Gruf
gRPC Ruby Framework
Stars: ✭ 411 (-2.84%)
Mutual labels:  rails
Annotate models
Annotate Rails classes with schema and routes info
Stars: ✭ 3,849 (+809.93%)
Mutual labels:  rails
Activity notification
Integrated user activity notifications for Ruby on Rails
Stars: ✭ 383 (-9.46%)
Mutual labels:  rails
Textbook Curriculum
Ada Developers Academy Online Curriculum
Stars: ✭ 396 (-6.38%)
Mutual labels:  rails
Rails Template
A best & newest & fastest rails 6.x template for senior rails developer.
Stars: ✭ 372 (-12.06%)
Mutual labels:  rails
Property web builder
The ultimate Ruby on Rails engine for creating real estate websites ⛺
Stars: ✭ 414 (-2.13%)
Mutual labels:  rails
Active delivery
Ruby framework for keeping all types of notifications (mailers, push notifications, whatever) in one place
Stars: ✭ 388 (-8.27%)
Mutual labels:  rails
Action args
Controller action arguments parameterizer for Rails 3+ & Ruby 1.9+
Stars: ✭ 409 (-3.31%)
Mutual labels:  rails
Second level cache
Write Through and Read Through caching library inspired by CacheMoney and cache_fu, support ActiveRecord 4, 5 and 6.
Stars: ✭ 380 (-10.17%)
Mutual labels:  rails
Deep pluck
Allow you to pluck attributes from nested associations without loading a bunch of records.
Stars: ✭ 385 (-8.98%)
Mutual labels:  rails
Localtower
Manage your Ruby On Rails models, relations, and migrations from a simple UI.
Stars: ✭ 401 (-5.2%)
Mutual labels:  rails
Angular Token
🔑 Token based authentication service for Angular with interceptor and multi-user support. Works best with devise token auth for Rails. Example:
Stars: ✭ 376 (-11.11%)
Mutual labels:  rails
Store model
Work with JSON-backed attributes as ActiveRecord-ish models
Stars: ✭ 410 (-3.07%)
Mutual labels:  rails
Suspenders
A Rails template with our standard defaults, ready to deploy to Heroku.
Stars: ✭ 3,748 (+786.05%)
Mutual labels:  rails
Refinerycms
An extendable Ruby on Rails CMS that supports Rails 6.0+
Stars: ✭ 3,825 (+804.26%)
Mutual labels:  rails
Rollbar Gem
Exception tracking and logging from Ruby to Rollbar
Stars: ✭ 414 (-2.13%)
Mutual labels:  rails
Hellraiser
Vulnerability scanner using Nmap for scanning and correlating found CPEs with CVEs.
Stars: ✭ 413 (-2.36%)
Mutual labels:  rails
Anyway config
Configuration library for Ruby gems and applications
Stars: ✭ 409 (-3.31%)
Mutual labels:  rails

Rambulance Build Status Gem Version

A simple and safe way to dynamically render error pages for Rails apps.

Features

Simple and Safe

Rambulance'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.

Flexible

You 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.

Easy installation and development

You don't have to configure things that every single person has to do and Rambulance does everything for you.

Installation and Usage

Add this line to your application's Gemfile:

gem 'rambulance'

And then execute:

$ rails g rambulance:install

Rambulance'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 or html2haml.

Now you can start editing templates like app/views/errors/not_found.html.erb. Edit, run rails server and open localhost:3000/rambulance/not_found!

Setting Pairs of Exceptions and HTTP Statuses

Open config/initializers/rambulance.rb and to configure the list of pairs of exception/corresponding http status. For example, if you want to display:

  • 422(unprocessable entity) for ActiveRecord::RecordNotUnique
  • 403(forbidden) for CanCan::AccessDenied
  • 404(not found) for YourCustomException

Then do the following:

# config/initializers/rambulance.rb
config.rescue_responses = {
  "ActiveRecord::RecordNotUnique" => :unprocessable_entity,
  "CanCan::AccessDenied"          => :forbidden,
  "YourCustomException"           => :not_found
}

Local Development

Open localhost:3000/rambulance/*** in Your Browser

Just open one of the error pages via Rambulance:

This is useful when you want to edit templates without changing Rails configuration.

Set consider_all_requests_local to false

Change config.consider_all_requests_local to false in config/environments/development.rb.

config.consider_all_requests_local = false

This 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.

Custom Exceptions App

If you want to do some more things in a exceptions app, you can also write your own custom exceptions app:

$ rails g rambulance:exceptions_app

It will generate your own custom exceptions app. You can use whatever techniques you want to use in controllers like before_filter and flash[:notice] = "message..." since it's a grandchild of ActionController::Base!

Heavily customizing the exceptions app is strongly discouraged as there would be no guard against bugs that occur in the exceptions app.

Testing

Rambulance 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:

Rspec:

include Rambulance::TestHelper

it "shows an error page" do
  with_exceptions_app do
    get '/does_not_exist'
  end

  assert_equal 404, response.status
end

Minitest:

include Rambulance::TestHelper

test "it shows an error page" do
  with_exceptions_app do
    get '/does_not_exist'
  end

  assert_equal 404, response.status
end

Note that testing error pages is not encouraged in Rails as it leads to overuse of the rescue_from DSL in controllers.

Supported Versions

  • Ruby 2.3, 2,4, 2,5, 2.6, trunk, JRuby 9.2, and JRuby head
  • Rails 4.2, 5.0, 5.1, 5.2, 6.0 and edge

Rambulance doesn't work with Rails 3.1 and below since they don't provide a way to use a custom exceptions app.

Contributing

  1. Fork it ( https://github.com/yuki24/rambulance/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

License

Copyright (c) 2014-2015 Yuki Nishijima. See LICENSE.txt for further details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].