Project

http-error

0.0
No commit activity in last 3 years
No release in over 3 years
Return HTTP error codes while rendering the corresponding error page in Rails.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

HTTP Error

This Rails plugin makes an http_error method available in ApplicationController which

  • returns the specified HTTP code in the response,
  • renders the correspondingly named HTML error document in public, and
  • returns false.

Returning false allows you to use http_error in before_filter’s to halt the filter chain.

Full documentation is at RubyDoc.info.

Example

The following will return a 404 HTTP code, render public/404.html, and halt the filter chain so that @user.destroy! is never executed.

class UserController < ApplicationController
  before_filter(:get_user)

  def delete
    @user.destroy
  end

  protected

  def get_user
    @user = User.find_by_id(params[:id])
    http_error(404) unless @user
  end
end

The get_user method above is better handled by the Declarative Find gem, but it illustrates use of http_error.

Colophon

See also

If you like this gem, you may also want to check out Declarative Find, Create New, or Save Changes To.

Tested with

  • Rails 3.0.5 — 20 May 2011

Contributing

To send patches, please fork on GitHub and submit a pull request.

Credits

© 2011 Cody Robbins. See LICENSE for details.