# How to use aggregates in a form

**URL:** <https://www.ruby-forum.com/t/how-to-use-aggregates-in-a-form/49289>\
**Category:** Rails\
**Created:** [December 2, 2005, 5:16am UTC](https://www.ruby-forum.com/t/how-to-use-aggregates-in-a-form/49289 "2005-12-02T05:16:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bohm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/59ef9b/32.png) [@Bohm](https://www.ruby-forum.com/u/Bohm)\
**Post date:** [December 2, 2005, 5:16am UTC](https://www.ruby-forum.com/t/how-to-use-aggregates-in-a-form/49289/1 "2005-12-02T05:16:08Z")

</div>

Hi,  
does anybody have a good way of handling aggregates in forms?

I have an aggregate object Money that is holds the price of an item. So  
my Item would contain a reference to Money:

```
composed_of :price,
                        :class_name => Money,
                        :mapping => [[:price_amount, :amount],
                                                 [:price_currency,

```

:currency]

Since the form helpers don’t support nesting, how do I display the price  
in the form?

Do I have to use a workaround something like:

Any help would be really appreciated 🙂

Thanks

Peter

---

<div class="post-metadata">

**Author:** ![Bohm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/59ef9b/32.png) [@Bohm](https://www.ruby-forum.com/u/Bohm)\
**Post date:** [December 2, 2005, 5:52am UTC](https://www.ruby-forum.com/t/how-to-use-aggregates-in-a-form/49289/2 "2005-12-02T05:52:33Z")

</div>

Hi Peter,

Maybe you could define a couple of methods to set and get according to  
your  
requriements

def price\_ammount  
some stuff  
end

def price\_ammount=(a\_price)  
some stuff  
end

Then in your view you could use those as though they are fields.

I think this should work, I haven’t tested it tho.

Cheers  
Dan

---

<div class="post-metadata">

**Author:** ![Bohm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/59ef9b/32.png) [@Bohm](https://www.ruby-forum.com/u/Bohm)\
**Post date:** [December 2, 2005, 8:06am UTC](https://www.ruby-forum.com/t/how-to-use-aggregates-in-a-form/49289/3 "2005-12-02T08:06:48Z")

</div>

* * *

Rails mailing list  
removed\_email\_address@domain.invalid  
[http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

---

<div class="post-metadata">

**Author:** ![Bohm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/59ef9b/32.png) [@Bohm](https://www.ruby-forum.com/u/Bohm)\
**Post date:** [December 3, 2005, 3:08pm UTC](https://www.ruby-forum.com/t/how-to-use-aggregates-in-a-form/49289/4 "2005-12-03T15:08:39Z")

</div>

Peter B. wrote:

> I only wish the rails supported nested parameters - for both  
> associations and aggregates 🙂

Peter, here’s the patch for this to which I referred in the  
earlier thread: [http://dev.rubyonrails.org/ticket/2053](http://dev.rubyonrails.org/ticket/2053)

–  
We develop, watch us RoR, in numbers too big to ignore.

---

<div class="post-metadata">

**Author:** ![Bohm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/59ef9b/32.png) [@Bohm](https://www.ruby-forum.com/u/Bohm)\
**Post date:** [December 3, 2005, 7:47pm UTC](https://www.ruby-forum.com/t/how-to-use-aggregates-in-a-form/49289/5 "2005-12-03T19:47:01Z")

</div>

Hi Mark,  
thank you very much - seems to be exactly what I need 🙂

It’s 2:35am - will have a look at it tomorrow morning

thanks

Peter
