Hi everyone. I faced with such problem:
My model Order accepts nested attributes for model Address. It belongs
to Address model and has shipping and billing address. I use nested
forms to update or create addresses and everything is fine but I need to
make an ability to mark checkobox 'use billing address for shipping' to
avoid user to fill shipping address form and just use the same data as
billing. So i can't understand how to do that. I receive attributes with
their proper ids from DB and I can't just tell 'If checkbox so
shipping_attributes = biling_attributes'. Here's my controller
def update
return redirect_to address_path if @order.update(order_params)
render :show
end
private
def init_order
@order = current_order
end
def order_params
params.require(:order).permit(shipping_address_attributes:
address_params,
billing_address_attributes:
address_params)
end
def address_params
%i(id first_name last_name street zip_code city phone country)
end
So I should write some condition in update action to perform this. But
how to do it most clearly???
--
Posted via
http://www.ruby-forum.com/.