Rails 2.0 rescue_from

class PostsController < ApplicationController
rescue_from ActiveRecord::RecordNotFound, :with => :deny_access
...
def show
   @post = Post.find_by_id(params[:id])
   raise ActiveRecord::RecordNotFound if @post.nil? #illegal access

That can be rewritten in a single line, since AR::Base.find precisely raises ActiveRecord::RecordNotFound if the record is not found:

   @post = Post.find(params[:id])

def deny_access
   respond_to do |format|
     format.html
   end
end

but the exception is not raised ... did I miss something ?

It should work, please debug this a little more.

-- fxn

Note that is neither your original code, nor the one I suggested.

Dynamic finders do no raise ActiveRecord::RecordNotFound, use AR::Base.find instead.

-- fxn

if you want find_by to raise, can overwrite your class method:

def self.find_by_something(something)
    super || raise(ActiveRecord::RecordNotFound, 'your own error
message')
end