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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bohm (Guest)
on 2005-12-02 06:16
(Received via mailing list)
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:
<input type="text" id="item_price_amount" name="item[price][amount]"
value="<%=@item.price.amount%>" />

Any help would be really appreciated :-)

Thanks

Peter
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
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
Bohm (Guest)
on 2005-12-02 09:06
(Received via mailing list)
_______________________________________________
Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails
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: http://dev.rubyonrails.org/ticket/2053


--
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

thanks

Peter
This topic is locked and can not be replied to.