flexi variants gem) and then add it to their cart. What I want to do is
save the customizations that are created in a new model (productbuilds)
when the cart form is submitted. I am trying to use the
accepts_nested_attributes_for method in rails and nesting productbuilds
under orders. I thought I had everything set up correctly and I am
receiving no errors, yet nothing is inserted into the productbuilds table.
I think the issue is in how I have it setup in the orders controller, but
I set it up as per any resource I have found. Any thoughts or suggestions?
*Controllers:*
*
*
*orders_conrtoller_decorator.rb*
def populate
@order = current_order(true)
@order.productbuilds.build
params[:products].each do |product_id,variant_id|
quantity = params[:quantity].to_i if !params[:quantity].is_a?(Hash)
quantity = params[:quantity][variant_id].to_i if
params[:quantity].is_a?(Hash)
@order.add_variant(Variant.find(variant_id), quantity,
ad_hoc_option_value_ids, product_customizations) if quantity > 0
end if params[:products]
params[:variants].each do |variant_id, quantity|
quantity = quantity.to_i
@order.add_variant(Variant.find(variant_id), quantity,
ad_hoc_option_value_ids, product_customizations) if quantity > 0
end if params[:variants]
fire_event('spree.cart.add')
fire_event('spree.order.contents_changed')
redirect_to cart_path
end
*Models:*
*order_decorator.rb*
*
*
module Spree
class Order < ActiveRecord::Base
attr_accessible :productbuilds_attributes
has_many :productbuilds
accepts_nested_attributes_for :productbuilds
end
end
*productbuild.rb*
module Spree
class Productbuild < ActiveRecord::Base
attr_accessible :order_id
belongs_to :order
end
end
*Views:*
*
*
*_cart_form.html*
*
*
<%= form_for :order, :url => populate_orders_url do |f| %>
<div id="inside-product-cart-form" data-hook="inside_product_cart_form"
itemprop="offers" itemscope itemtype="http://schema.org/Offer">
<%= f.fields_for :productbuilds do |productbuild_form| %>
<%= productbuild_form.hidden_field :tops_size, :value => "Small"%>
<%= productbuild_form.hidden_field :tops_style, :value => "Tri Top" %>
<% end %>
............
<% end %>
--
You received this message because you are subscribed to the Google Groups "Spree" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.