# Design question - errors and exceptions

**URL:** <https://www.ruby-forum.com/t/design-question-errors-and-exceptions/135423>\
**Category:** Rails\
**Created:** [April 22, 2008, 2:29am UTC](https://www.ruby-forum.com/t/design-question-errors-and-exceptions/135423 "2008-04-22T02:29:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jordelver](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@jordelver](https://www.ruby-forum.com/u/jordelver)\
**Post date:** [April 22, 2008, 2:29am UTC](https://www.ruby-forum.com/t/design-question-errors-and-exceptions/135423/1 "2008-04-22T02:29:32Z")

</div>

Hi,  
I hope someone can help, this is driving me mad.

I’m adding different postage methods to my cart which are user  
selectable.  
A cart can have only one postage method, and a postage method can have  
many rates. So, I have this:

class Cart \< ActiveRecord::Base  
belongs\_to :postage\_method  
end

class PostageMethod \< ActiveRecord::Base  
has\_one :cart  
has\_many :rates, :class\_name =\> ‘PostageRate’  
end

class PostageRate \< ActiveRecord::Base  
belongs\_to :postage\_method  
end

What I’m doing is updating the cart postage cost attribute every time  
the the cart is updated (add item, remove item, etc). This is based on  
the total weight in the cart. I have data like this for each postage  
method.

lower upper price  
0 100 1.25  
101 200 1.50  
201 300 1.75

So, my questions.

1. Should I dump the database table and put this in a non ActiveRecord  
class?  
I don’t know if I’m over complicating this when I know there will  
probably only ever be two postage methods.

2. If the user chooses the method which has a limit, and the cart is  
over that limit, I was going to automatically change the users postage  
method and recalculate their postage using the new postage method. I  
need to show the user a message explaining this. The problem is, how  
to I propagate that message up through two different objects to the  
controller? Do I throw a PostageChanged exception and then catch it in  
my controller? The problem with doing that is that my database update  
is then rolled back because I am throwing an exception within an  
ActiveRecord model.

Is there a way to get active record to not rollback on an exception  
thrown?

How would you handle this sort of problem?

Any advice would be appreciated.

Cheers,  
Jordan

---

<div class="post-metadata">

**Author:** ![jordelver](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@jordelver](https://www.ruby-forum.com/u/jordelver)\
**Post date:** [April 22, 2008, 2:51am UTC](https://www.ruby-forum.com/t/design-question-errors-and-exceptions/135423/2 "2008-04-22T02:51:10Z")

</div>

On Apr 21, 2008, at 6:28 PM, Jordan E. wrote:

> belongs\_to :postage\_method  
> end
> 
> class PostageMethod \< ActiveRecord::Base  
> has\_one :cart  
> has\_many :rates, :class\_name =\> ‘PostageRate’  
> end
> 
> class PostageRate \< ActiveRecord::Base  
> belongs\_to :postage\_method  
> end

Looks like the cart ought to own the postage method, not the other way  
around. That should make your other issues much simpler.

---

<div class="post-metadata">

**Author:** ![jordelver](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@jordelver](https://www.ruby-forum.com/u/jordelver)\
**Post date:** [April 22, 2008, 12:36pm UTC](https://www.ruby-forum.com/t/design-question-errors-and-exceptions/135423/3 "2008-04-22T12:36:57Z")

</div>

Hi,

> Looks like the cart ought to own the postage method, not the other way  
> around. That should make your other issues much simpler.

Thanks, but how would that make my issues simpler?

How do I send a signal to the controller to show what has happened?  
Anyone?

Thank you 🙂
