Class: Admin::Shop::Products::VariantsController
- Inherits:
-
ResourceController
- Object
- ResourceController
- Admin::Shop::Products::VariantsController
- Defined in:
- app/controllers/admin/shop/products/variants_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
-
#sort ⇒ Object
PUT /admin/shop/products/1/variants/sort PUT /admin/shop/products/1/variants/sort.js PUT /admin/shop/products/1/variants/sort.json AJAX and HTML —————————————————————————-.
Instance Method Details
#create ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/controllers/admin/shop/products/variants_controller.rb', line 7 def create notice = 'Successfully created variant.' error = 'Could not create variant.' begin @shop_product_variant.attributes = params[:shop_product_variant] @shop_product_variant.save! respond_to do |format| format.html { redirect_to edit_admin_shop_product_path(@shop_product) } format.js { render :partial => '/admin/shop/products/edit/shared/variant', :locals => { :variant => @shop_product_variant } } end rescue respond_to do |format| format.html { flash[:error] = error redirect_to edit_admin_shop_product_path(@shop_product) } format.js { render :text => error, :status => :unprocessable_entity } end end end |
#destroy ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/controllers/admin/shop/products/variants_controller.rb', line 66 def destroy notice = 'Successfully destroyed variant.' error = 'Could not destroy variant.' if @shop_product_variant.destroy respond_to do |format| format.html { redirect_to edit_admin_shop_product_path(@shop_product) } format.js { render :text => notice, :status => :ok } end else respond_to do |format| format.html { flash[:error] = error redirect_to edit_admin_shop_product_path(@shop_product) } format.js { render :text => error, :status => :unprocessable_entity } end end end |
#sort ⇒ Object
PUT /admin/shop/products/1/variants/sort PUT /admin/shop/products/1/variants/sort.js PUT /admin/shop/products/1/variants/sort.json AJAX and HTML
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/controllers/admin/shop/products/variants_controller.rb', line 36 def sort notice = 'Successfully sorted Variants.' error = 'Could not sort Variants.' begin @shop_product = ShopProduct.find(params[:product_id]) @variants = CGI::parse(params[:variants])['variants[]'] @variants.each_with_index do |id, index| ShopProductVariant.find(id).update_attributes!({ :position => index+1 }) end respond_to do |format| format.html { redirect_to edit_admin_shop_product_path(@shop_product) } format.js { render :partial => '/admin/shop/products/edit/shared/variant', :collection => @shop_product.variants } format.json { render :json => @shop_product.variants.to_json } end rescue respond_to do |format| format.html { flash[:error] = error redirect_to edit_admin_shop_product_path(@shop_product) } format.js { render :text => error, :status => :unprocessable_entity } format.json { render :json => { :error => error }, :status => :unprocessable_entity } end end end |