Ruby on Rails Monday, July 25, 2016

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

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/6ddcdf201a1ea30512b8cb3f80da9388%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment