Forum: Ruby on Rails how to use aggregates in a form

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Bohm (Guest)
on 2005-12-02 06:16
(Received via mailing list)
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],

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:
<input type="text" id="item_price_amount" name="item[price][amount]"
value="<%=@item.price.amount%>" />

Any help would be really appreciated :-)


Daniel -. (Guest)
on 2005-12-02 06:52
(Received via mailing list)
Hi Peter,

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

def price_ammount
 some stuff

def price_ammount=(a_price)
 some stuff

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

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

Bohm (Guest)
on 2005-12-02 09:06
(Received via mailing list)
Rails mailing list
mrj (Guest)
on 2005-12-03 16:08
(Received via mailing list)
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:

We develop, watch us RoR, in numbers too big to ignore.
Bohm (Guest)
on 2005-12-03 20:47
(Received via mailing list)
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


This topic is locked and can not be replied to.