# Design-Problem

**URL:** <https://www.ruby-forum.com/t/design-problem/72472>\
**Category:** Rails\
**Created:** [October 17, 2006, 2:08pm UTC](https://www.ruby-forum.com/t/design-problem/72472 "2006-10-17T14:08:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [October 17, 2006, 2:08pm UTC](https://www.ruby-forum.com/t/design-problem/72472/1 "2006-10-17T14:08:21Z")

</div>

hi @ all

I’ve a design problem in my ror-project. I’m using a simple  
rails-application to manage some data. I would like to present  
percentage-numbers in different views. But I want to save the  
percentages as a decimal number in the database.

When I save or read a record, is that the job for the controller or the  
model, to present me the percentage number (not the saved decimal  
number)? Why?

Thanks for the solutions…

---

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [October 17, 2006, 2:33pm UTC](https://www.ruby-forum.com/t/design-problem/72472/2 "2006-10-17T14:33:42Z")

</div>

On 17 Oct 2006, at 13:08, M. R. wrote:

> I’ve a design problem in my ror-project. I’m using a simple  
> rails-application to manage some data. I would like to present  
> percentage-numbers in different views. But I want to save the  
> percentages as a decimal number in the database.
> 
> When I save or read a record, is that the job for the controller or  
> the  
> model, to present me the percentage number (not the saved decimal  
> number)? Why?

Neither, it’s a view responbsibility, ideally using a helper  
function. Why? Because it’s about formatting and presentation.

number\_to\_percentage() will do the job nicely.

Paul

---

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [October 17, 2006, 2:35pm UTC](https://www.ruby-forum.com/t/design-problem/72472/3 "2006-10-17T14:35:51Z")

</div>

Paul L. wrote:

> On 17 Oct 2006, at 13:08, M. R. wrote:

> Neither, it’s a view responbsibility, ideally using a helper  
> function. Why? Because it’s about formatting and presentation.
> 
> number\_to\_percentage() will do the job nicely.

But when I use the number for a calculation before I present it on a  
view? Is it a controller-task?

---

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [October 19, 2006, 2:45am UTC](https://www.ruby-forum.com/t/design-problem/72472/4 "2006-10-19T02:45:58Z")

</div>

On 10/17/06, M. R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> But when I use the number for a calculation before I present it on a  
> view? Is it a controller-task?

Probably a model task. Depends on what your calculating an for what  
purpose. For example calculating the total value of an order across  
all the order line items is certainly a model responsibility. Adding  
up a whole bunch of numbers that the user has ticked on a form would  
be more in the controller’s domain.

Cheers,  
Max

---

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [October 20, 2006, 7:51am UTC](https://www.ruby-forum.com/t/design-problem/72472/5 "2006-10-20T07:51:05Z")

</div>

On 10/19/06, M. R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > all the order line items is certainly a model responsibility. Adding
> 
> Is it a controller or model task?
> 
> The newbie need help. Thanks for your solution!

I’d put it in the model. It is clearly a business-logic-type task.

Max

---

<div class="post-metadata">

**Author:** ![flnative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5daacb/32.png) [@flnative](https://www.ruby-forum.com/u/flnative)\
**Post date:** [October 19, 2006, 9:13am UTC](https://www.ruby-forum.com/t/design-problem/72472/6 "2006-10-19T09:13:12Z")

</div>

Max M. wrote:

> On 10/17/06, M. R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > But when I use the number for a calculation before I present it on a  
> > view? Is it a controller-task?
> 
> Probably a model task. Depends on what your calculating an for what  
> purpose. For example calculating the total value of an order across  
> all the order line items is certainly a model responsibility. Adding  
> up a whole bunch of numbers that the user has ticked on a form would  
> be more in the controller’s domain.
> 
> Cheers,  
> Max

Every day, the user ticked on a form some percentage changes in. With  
this number and some saved records from the database, I calculate a  
value. This calculated value and the percentage change are saved in the  
database.

Is it a controller or model task?

The newbie need help. Thanks for your solution!
