Module: CodyRobbins::HttpError::InstanceMethods

Defined in:
lib/cody_robbins/http_error/instance_methods.rb

Instance Method Summary collapse

Instance Method Details

#http_error(code) ⇒ boolean (protected)

Returns the specified HTTP code in the action’s response, renders the correspondingly named HTML error document in public, and returns false. If a corresponding HTML error document doesn’t exist, you’ll probably get some sort of exception.

Examples:

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


28
29
30
31
32
33
# File 'lib/cody_robbins/http_error/instance_methods.rb', line 28

def http_error(code)
  render(:file => Rails.root.join('public', "#{code}.html"),
         :layout => false,
         :status => code)
  return(false)
end