GithubHelp home page GithubHelp logo

goalie's Introduction

Goalie

Goalie is a flexible dynamic error response renderer for Rails built on Rack and Rails Engines. It provides the same default error pages as Rails, but allows you to easily customize them with dynamic content. This means you can use your application layout, have different error pages for different subdomains, and do all sorts nice things.

Installation

gem install goalie

After you install it and add it to your Gemfile, you have to require it together with Rails' frameworks at the top of your config/application.rb file:

require 'goalie/rails'

This will remove Rails' default exception renderer middleware (ShowExceptions) and use Goalie's instead. Unless you have custom static pages in your public directory (which we plan to support later), this will be a drop-in replacement.

Customization

Controllers

The public (production) rescuing of errors is done by the PublicErrorsController found in Goalie's app/controllers directory. If you create a controller with the same name, it will automatically be used instead of Goalie's. All it needs to do is support the following actions:

  • internal_server_error
  • not_found
  • unprocessable_entity
  • conflict
  • method_not_allowed
  • not_implemented

If you don't actually need a separate action for each of these errors, you can redirect them to others, for example, with:

def unprocessable_entity
  render :action => 'internal_server_error'
end

Views

You can also customize only the views and use Goalie's default controller. All you need is to have inside app/views/public_errors views with the same names as the actions listed above.

Besides the standard stuff that Rails makes available to views, you will also have access to the following instance variables if you include the Goalie::ErrorDetails module:

  • @request
  • @exception
  • @application_trace
  • @framework_trace
  • @full_trace

Be VERY careful when using this in production, as you could expose sensitive information inside the request and exception. Generally, you probably shouldn't use these variables at all. The only place it makes sense is to have a more detailed error screen for admins or other high-level users. By default these details are not available to the public errors views but can be made available if you override the PublicErrorsController and include the Goalie::ErrorDetails module.

Credit

Goalie copies a lot of code and ideas from:

  • Rails' ShowExceptions middleware
  • Rails' default error views
  • Rails' exception_notification plugin

Which are mostly the work of Joshua Peek, with help from various contributors. We're highly indebted to them and thank them a lot for their work.

Contributions

Any form of feedback, patches, issues, and documentation are highly appreciated.

License

MIT license. Copyright 2010 Helder Ribeiro.

goalie's People

Contributors

adamcooper avatar direction avatar

Stargazers

Lucas Caton avatar Sergey Besedin avatar Cristian Molina avatar Joe Pestro avatar Kain avatar Jason Filipe avatar Dave Zohrob avatar Thomas Klemm avatar Wei Zhu avatar Gary Lai avatar Lukasz Mlodzik avatar Jacob Bijani avatar Jun Lin avatar Martin Tithonium avatar Sascha Hoellger avatar Björn Wolf avatar Bart avatar Lev Brie avatar Dave Perrett avatar Josh Cutler avatar Angel Carballo avatar Jacques Crocker avatar Zhomart Mukhamejanov avatar yujingzhou avatar Maciek Gajewski avatar Daniel Fagnan avatar  avatar Blake Jakopovic avatar Jason Lewis avatar Marco Singer avatar pinglamb avatar Mykhaylo Skvyrskyi avatar Lau avatar Brandon Hornseth avatar Slipstream Studio avatar Buts Johan avatar Karl Baum avatar Jason Weathered avatar Jeff Heuer avatar Peter P. Gengler avatar Khaled Ayoubi avatar Robert Sęk avatar Yomi Colledge avatar Cyrille Stepanyk avatar Florian Dütsch avatar Michael Reinsch avatar Peter Boling avatar  avatar Paweł Gościcki avatar  avatar Andreas Haller avatar Jorge Cuadrado avatar Aaron Eisenberger avatar Helder S Ribeiro avatar  avatar Cleiton Francisco avatar Colin Schlueter avatar Aris avatar

goalie's Issues

Can't access current_user (devise) in dynamic error pages

Hi,

I tried out your gem this morning and it looks like a very promising solution to (what I see) as a problem in Rails 3. After trying differing solutions all morning yours is the only solid one. I'm very close to getting it working fully but have two issues off getting it perfect.

The first is that my current_user (via devise) is throwing an error

  Error during failsafe response: ActionView::Template::Error

/Users/jack/.rvm/gems/ruby-1.9.2-p0/gems/activemodel-3.0.3/lib/active_model/attribute_methods.rb:364:in method_missing' /Users/jack/.rvm/gems/ruby-1.9.2-p0/gems/activerecord-3.0.3/lib/active_record/attribute_methods.rb:46:inmethod_missing'
/Users/jack/Code/oxnotes3/app/helpers/application_helper.rb:3:in current_seller' /Users/jack/Code/oxnotes3/site/app/views/shared/_nav_bar.html.erb:2:in_site_app_views_shared__nav_bar_html_erb___737376405_689060__547631846'
/Users/jack/.rvm/gems/ruby-1.9.2-p0/gems/actionpack-3.0.3/lib/action_view/template.rb:135:in `block in render'

The second (related) is that some of my preferences (e.g. image to be displayed on layout) is determined at db level and this isn't working either.

I'm thinking this might mean that Goalie is having issues db issues? Any ideas? Roads I should explore?

Jack

Missing template error

Using Rails 3.0.5, Ubuntu 10, goalie 0.0.4
Followed the instructions but for certain actions I get the following error in the logfile

Error during failsafe response: Missing template public_errors/internal_server_error ....

The directory public_errors exist, and the file internal_server_error.html and internal_server_error.html.erb exists.

The web browser displays the standard Rails error 500 (?)

500 Internal Server Error
If you are the administrator of this website, then please read this web application's log file and/or the web server's log file to find out what went wrong.

The controller is per your example, but using a layout

class PublicErrorsController < ApplicationController
  layout "fatal_errors"
  #403
  def forbidden
  end

  #404
  def not_found
  end

  #405
  def method_not_allowed
    render :action => 'internal_server_error'
  end

  #409
  def conflict
    render :action => 'internal_server_error'
  end

  #422
  def unprocessable_entity
  end

  #500
  def internal_server_error
  end

  #501
  def not_implemented
    render :action => 'internal_server_error'
  end
end

Doesn't use application layout by default

Using Goalie's PublicErrorsController (i.e. not overriding it) will render your public_errors views, but without the application layout.

If you override the controller with your own, the application layout is used.

Is this intentional?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.