# Prices and discounts

**URL:** <https://www.ruby-forum.com/t/prices-and-discounts/127462>\
**Category:** Rails\
**Created:** [January 29, 2008, 3:04pm UTC](https://www.ruby-forum.com/t/prices-and-discounts/127462 "2008-01-29T15:04:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [January 29, 2008, 3:04pm UTC](https://www.ruby-forum.com/t/prices-and-discounts/127462/1 "2008-01-29T15:04:11Z")

</div>

I’m trying to solve a problem for a client.

It’s a language school.

They have, courses so I have a Courses model and table.

Each course has a name and a description and a price\_per\_week field (a  
base price if you like).All is fine, or should I say, was fine.The  
client now wants to charge different prices depending on the length of  
the students course.

e.g.

1-2 weeks - price\_per\_week \* 1.0  
3-4 weeks - price\_per\_week \* 0.9  
5-6 weeks - price\_per\_week \* 0.8  
7-8 weeks - price\_per\_week \* 0.7  
8 weeks+ - price\_per\_week \* 0.6

* * *

My plan is to do the following,

Introduce a Discounts model.

Something like

:period (integer)  
:name (string)  
:discount (integer)

I’ll fill it with the five time periods above.

I presume I need in my Courses model

has\_many :discounts

and in Discounts

belongs\_to :course

* * *

If my plans basically correct, can someone give me an example of how I  
would then render a table of prices by period in a view. I’m thinking of  
using a partial for this if possible so I can put price tables up for a  
particular course where I need them?

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [January 29, 2008, 5:00pm UTC](https://www.ruby-forum.com/t/prices-and-discounts/127462/2 "2008-01-29T17:00:04Z")

</div>

anybody shed any light on this one? Is my approach sound?
