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
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 On 12/2/05, Peter Bohm <Bohm-+Ou9gZH0t5G+51mZqJFLXQ@public.gmane.org> wrote:> > 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="<%=-oJWR6z7W/o+QwGVeCRXvBV6hYfS7NtTn@public.gmane.org%>" /> > > Any help would be really appreciated :-) > > Thanks > > Peter > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Hi Dan, thank you very much for help I only wish the rails supported nested parameters - for both associations and aggregates :-) Thanks Peter Liquid wrote: 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 On 12/2/05, Peter Bohm <Bohm-+Ou9gZH0t5G+51mZqJFLXQ@public.gmane.org > wrote: 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: value="<%@item.price.amount%>" /> Any help would be really appreciated :-) Thanks Peter _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Peter Bohm 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.
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 Mark Reginald James wrote:> Peter Bohm 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 > >