# Exception in Rails

**URL:** <https://www.ruby-forum.com/t/exception-in-rails/133456>\
**Category:** Rails\
**Created:** [March 31, 2008, 7:08pm UTC](https://www.ruby-forum.com/t/exception-in-rails/133456 "2008-03-31T19:08:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [March 31, 2008, 7:08pm UTC](https://www.ruby-forum.com/t/exception-in-rails/133456/1 "2008-03-31T19:08:37Z")

</div>

It continues with the same error. I have created with a scaffold a  
posts\_controller:

class PostsController \< ApplicationController  
rescue\_from Activerecord::NoMethodError. with =\> :not\_found

protected  
def not\_found  
Code  
end

end

But it gives me the same error when I go to some view: NoMethod error.  
What’s is it wrong?

---

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [March 31, 2008, 10:23pm UTC](https://www.ruby-forum.com/t/exception-in-rails/133456/2 "2008-03-31T22:23:12Z")

</div>

On 31 Mar 2008, at 18:08, John S. wrote:

> It continues with the same error. I have created with a scaffold a  
> posts\_controller:
> 
> class PostsController \< ApplicationController  
> rescue\_from Activerecord::NoMethodError. with =\> :not\_found

You’ve got several typos in here. What’s actually in your posts  
controller?  
In addition NoMethodError sounds like a bad thing to be rescuing like  
this. What’s the real problem you’re trying to solve?

Fred

---

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [April 1, 2008, 8:50am UTC](https://www.ruby-forum.com/t/exception-in-rails/133456/3 "2008-04-01T08:50:53Z")

</div>

Frederick C. wrote:

> On 31 Mar 2008, at 18:08, John S. wrote:
> 
> > It continues with the same error. I have created with a scaffold a  
> > posts\_controller:
> > 
> > class PostsController \< ApplicationController  
> > rescue\_from Activerecord::NoMethodError. with =\> :not\_found
> 
> You’ve got several typos in here. What’s actually in your posts  
> controller?  
> In addition NoMethodError sounds like a bad thing to be rescuing like  
> this. What’s the real problem you’re trying to solve?
> 
> Fred

For example, considerar I have an object named product. This product has  
a price. If I destroy that product and go to a ticket index view  
(showinng ID, client name and product) I get NoMethodError with  
ticket.product.price. Of course, if I don’t destroy that product, I  
don’t get that error.

---

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [April 1, 2008, 8:51am UTC](https://www.ruby-forum.com/t/exception-in-rails/133456/4 "2008-04-01T08:51:05Z")

</div>

Frederick C. wrote:

> On 31 Mar 2008, at 18:08, John S. wrote:
> 
> > It continues with the same error. I have created with a scaffold a  
> > posts\_controller:
> > 
> > class PostsController \< ApplicationController  
> > rescue\_from Activerecord::NoMethodError. with =\> :not\_found
> 
> You’ve got several typos in here. What’s actually in your posts  
> controller?  
> In addition NoMethodError sounds like a bad thing to be rescuing like  
> this. What’s the real problem you’re trying to solve?
> 
> Fred

For example, considerar I have an object named product. This product has  
a price. If I destroy that product and go to a ticket index view  
(showinng ID, client name and product) I get NoMethodError with  
ticket.product.price. Of course, if I don’t destroy that product, I  
don’t get that error.

---

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [April 1, 2008, 9:57am UTC](https://www.ruby-forum.com/t/exception-in-rails/133456/5 "2008-04-01T09:57:37Z")

</div>

Yeah I’ve often lamented the fact that we need a “halt dot-method  
chain” in ruby.

Julian.

Learn about Ruby on Rails! CHECK OUT THE FREE VIDS (LIMITED TIME) NEW  
VIDEO OUT 3rd APRIL  
[http://sensei.zenunit.com/](http://sensei.zenunit.com/)

---

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [April 1, 2008, 9:04am UTC](https://www.ruby-forum.com/t/exception-in-rails/133456/6 "2008-04-01T09:04:17Z")

</div>

Oh dear god!

def show  
@product = Product.find(params[:id])  
rescue ActiveRecord::RecordNotFound  
not\_found  
end

protected

def not\_found  
your\_code\_here  
end

Is it really that hard?
