Let's say I have a standalone User model and Service model.
I also have a Order model that holds the orders created by an user for a service. I'm wondering how I could properly create an order entry in rails.
Here is how I'll create an order entry if it refers to only one other model, say user.
@order = current_user.orders.build(params[:order])
@order.save
Now how do I do that if order refers to multiple models (user and service)?
Assume that Order model has user_id and service_id attributes and all model objects are properly tagged with belongs_to and has_many relationships.
@order = Order.new(params[:order])
@order.user = current_user
@order.service = @service
@order.save
Where @service
is some your fetched Service
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With