Has_one question

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?

Josh wrote:

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