Asking for best practice to list nested attributes in show action when you need to paste them in various places..
I have two models: Product & ProductDetail, ProductDetails belongs to Product, Product has_many ProductDetails. Within forms and nested renders it works like a charm, no issues (especially after RailsCast 196/197 by Ryan (thanks boet!)
Now, I need to issue view for my product. Basically it is just a product in commerce.
So in my controllers I have regular things like
@product = Product.find ...
@product_details = @product.product_details.build
When in show action view
[email protected]
[email protected]
[email protected]
-@product_details.each do |d|
=d.attribute1
=d.attribute2
... some other view details here..
-@product_details.each do |d|
=d.attribute3
=d.attribute3
As you can see I put loops into view several time as I need show them in various places.
I wonder to know what is best practice (may be arrays make sense for here), please suggest.
I'am planning to extend page functionality by using radio buttons and jQuery events for changing (i.e. price) and values of certain field, which at the end changes price and order detail.
Would be great to get some good reading / example of rails + js combination specifically for nested models and its attributes.. the other thing is that I am planning to build number of nested models around main product and show them / update / edit etc based on client behavior. Is there any best practice on number of nested models per model ?