# Method or controller?

**URL:** <https://www.ruby-forum.com/t/method-or-controller/168774>\
**Category:** Rails\
**Created:** [May 25, 2009, 5:59pm UTC](https://www.ruby-forum.com/t/method-or-controller/168774 "2009-05-25T17:59:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [May 25, 2009, 5:59pm UTC](https://www.ruby-forum.com/t/method-or-controller/168774/1 "2009-05-25T17:59:52Z")

</div>

I wish to allow users to view collections of foreign currency exchange  
(forex) rates in the following manners:

1. All currencies, only the most current forex rate.

and

1. One currency, the N most recent rates.

I seem to have several choices here:

A. Use the controller for the rates model and use the index method for  
case 1 and the show method for case 2.

B. Use the controller for the rates model and use the index method for  
case 1 and create a new method, current, for case 2.

C. Use two controllers and use the index method in the controller for  
the rates model (forex\_rates\_controller) to list all currencies and all  
rates, which is generally the default index behavior; while in the  
second (current\_forex\_rates\_controller) use index and show as specified  
in alternative A.

Are there any strong preferences for going one way over the other?

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [May 25, 2009, 6:29pm UTC](https://www.ruby-forum.com/t/method-or-controller/168774/2 "2009-05-25T18:29:58Z")

</div>

I am having difficulty understanding the problem, not knowing about  
forex  
rates. Could you explain the model structure? I know that controllers  
do  
not need to map to models but I think it will help me to understand the  
structure.

Colin

2009/5/25 James B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [May 25, 2009, 7:28pm UTC](https://www.ruby-forum.com/t/method-or-controller/168774/3 "2009-05-25T19:28:01Z")

</div>

Colin L. wrote:

> I am having difficulty understanding the problem, not knowing about  
> forex rates. Could you explain the model structure?

NP.

There is but one model involved. It contains a collection of currency  
pairs (CAD/USD, CAD/GBP, CAD/JPY, etc.) with specific dates and the  
exchange rate in effect on that date. So

forex.base  
forex.quote  
forex.date  
forex.rate

A given pair and date only occurs once in the table (composite unique  
index).

Standard Rails convention has the index action returning all rates for  
all currency pairs. This is probably not much use in this application.  
The show action returns a specific rate for a specific pair and date.  
This is probably useful as is.

Users are typically interested in two additional view: The most recent  
N rates for a specific currency pair; and the rates for all currency  
pairs on a specific date.

---

<div class="post-metadata">

**Author:** ![byrnejb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/d2c977/32.png) [@byrnejb](https://www.ruby-forum.com/u/byrnejb)\
**Post date:** [May 25, 2009, 10:59pm UTC](https://www.ruby-forum.com/t/method-or-controller/168774/4 "2009-05-25T22:59:40Z")

</div>

Have you considered having a currencies controller? The fact that you  
talk  
about currencies suggests that they may the principle resource of  
interest  
to the user, even though they do not directly map to a model. The index  
method would then show all currencies, possibly with a parameter(s) to  
indicate whether the most recent rates for each currency should be  
shown,  
the rates at a particular date, the rate against another particular  
currency  
or whatever. The show method would show information for just one  
currency,  
again parametrised if necessary.

Colin

2009/5/25 James B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
