Josh wrote:> i have my orders and addresses in separate tables. in the Order model
> file i have has_one :address
>
> i have an address form that when submitted the first time, will create
> an address for the order, but if it needs to be submitted again, it
> should update the existing address instead of creating a new one.
>
> in my controller i have this piece of code:
>
> if @order.has_address?
> @order.address.update_attributes(params[:address])
> else
> @order.create_address(params[:address])
> end
>
> just seems like there would be a more elegant way of doing this... or
> am i being too picky?
Perhaps:
@order.build_address unless @order.address
@order.address.update_attributes(params[:address])
--
We develop, watch us RoR, in numbers too big to ignore.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---