404 handling

This commit is contained in:
Marcin Kulik 2011-11-23 21:46:18 +01:00
parent 139d6144de
commit 2abdf89511
9 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/

View File

@ -0,0 +1,3 @@
// Place all the styles related to the exceptions controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -1,3 +1,7 @@
class NotFound < StandardError; end
class ApplicationController < ActionController::Base
protect_from_forgery
rescue_from(NotFound) { render 'exceptions/not_found' }
end

View File

@ -0,0 +1,10 @@
class ExceptionsController < ApplicationController
def not_found
respond_to do |format|
format.any { render :text => 'Requested resource not found', :status => 404 }
format.html { render :status => 404 }
end
end
end

View File

@ -0,0 +1,2 @@
module ExceptionsHelper
end

View File

@ -0,0 +1 @@
404 dude

View File

@ -55,4 +55,6 @@ AsciiIo::Application.routes.draw do
# This is a legacy wild controller route that's not recommended for RESTful applications.
# Note: This route will make all actions in every controller accessible via GET requests.
# match ':controller(/:action(/:id(.:format)))'
match "*a", :to => "exceptions#not_found"
end

View File

@ -0,0 +1,5 @@
require 'spec_helper'
describe ExceptionsController do
end

View File

@ -0,0 +1,15 @@
require 'spec_helper'
# Specs in this file have access to a helper object that includes
# the ExceptionsHelper. For example:
#
# describe ExceptionsHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# helper.concat_strings("this","that").should == "this that"
# end
# end
# end
describe ExceptionsHelper do
pending "add some examples to (or delete) #{__FILE__}"
end