# Rescue\_from for NoMethodError

**URL:** <https://www.ruby-forum.com/t/rescue-from-for-nomethoderror/159962>\
**Category:** Rails\
**Created:** [February 10, 2009, 1:15pm UTC](https://www.ruby-forum.com/t/rescue-from-for-nomethoderror/159962 "2009-02-10T13:15:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shahroon\_ali](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@shahroon\_ali](https://www.ruby-forum.com/u/shahroon_ali)\
**Post date:** [February 10, 2009, 1:15pm UTC](https://www.ruby-forum.com/t/rescue-from-for-nomethoderror/159962/1 "2009-02-10T13:15:07Z")

</div>

Hi everyone,  
I was just trying to catch some exceptions in my  
app,  
for “Record Not Found” I used this  
in my application.rb file  
rescue\_from ActiveRecord::RecordNotFound, :with =\> :record\_not\_found  
rescue\_from ActionController::NoMethodError, :with =\> :show\_error

private

def record\_not\_found  
render :text =\> “404 Not Found”, :status =\> 404  
end  
def show\_error(exception)  
render :text =\> exception.message;  
end

and was quite successful but for “NoMethodError” I am trying the same  
but It  
isn’t working at all. Can anybody help me?  
Thanks in advance,  
Shahroon

---

<div class="post-metadata">

**Author:** ![shahroon\_ali](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@shahroon\_ali](https://www.ruby-forum.com/u/shahroon_ali)\
**Post date:** [February 11, 2009, 8:03am UTC](https://www.ruby-forum.com/t/rescue-from-for-nomethoderror/159962/2 "2009-02-11T08:03:20Z")

</div>

Oh Yeah my mistake it was  
rescue\_from NoMethodError, :with =\> :show\_error  
but now I am following this procedure but no success in “NoMethodError”

rescue\_from NameError, :with =\> :handle\_exceptions  
rescue\_from NoMethodError, :with =\> :handle\_exceptions  
rescue\_from ActiveRecord::Rollback, :with =\> :handle\_exceptions  
rescue\_from ActiveRecord::StatementInvalid, :with =\>  
:handle\_exceptions  
rescue\_from ActiveRecord::RecordNotFound, :with =\> :handle\_exceptions  
rescue\_from ActionController::UnknownAction, :with =\>  
:handle\_exceptions  
rescue\_from ActiveRecord::RecordNotFound, :with =\> :handle\_exceptions  
rescue\_from ActiveRecord::StaleObjectError, :with =\>  
:handle\_exceptions  
rescue\_from ActiveRecord::RecordInvalid, :with =\> :handle\_exceptions  
rescue\_from ActiveRecord::RecordNotSaved, :with =\> :handle\_exceptions  
rescue\_from ActionController::MethodNotAllowed, :with =\>  
:handle\_exceptions  
rescue\_from ActionController::MethodNotAllowed, :with =\>  
:handle\_exceptions  
rescue\_from ActionController::InvalidAuthenticityToken, :with =\>  
:handle\_exceptions

private

def handle\_exceptions  
render :action =\> ‘500.html’,:text =\> ‘This is an error’, :status =\>  
500  
end

Any ideas how to solve this problem?

Shahroon

On Tue, Feb 10, 2009 at 9:02 PM, Frederick C. \<

---

<div class="post-metadata">

**Author:** ![shahroon\_ali](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@shahroon\_ali](https://www.ruby-forum.com/u/shahroon_ali)\
**Post date:** [February 10, 2009, 5:02pm UTC](https://www.ruby-forum.com/t/rescue-from-for-nomethoderror/159962/3 "2009-02-10T17:02:56Z")

</div>

On 10 Feb 2009, at 12:14, shahroon ali wrote:

> ```
> render :text => "404 Not Found", :status => 404
> 
> ```
> 
> end  
> def show\_error(exception)  
> render :text =\> exception.message;  
> end
> 
> and was quite successful but for “NoMethodError” I am trying the  
> same but It isn’t working at all. Can anybody help me?

Because ActionController::NoMethodError doesn’t exist. It’s just plain  
NoMethodError (possibly ::NoMethodError but I don’t think that’s  
needed here)

Fred
