Guest User

Untitled

a guest
May 27th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. class ProductsController < ApplicationController
  2. # GET /products
  3. # GET /products.xml
  4. #before_filter :login_required
  5. before_filter {privilege_required('sales')}
  6. def index
  7.  
  8. #@products = Product.find(:all)
  9. @products = Product.search(params[:search], params[:page])
  10.  
  11. respond_to do |format|
  12. format.html # index.html.erb
  13. format.xml { render :xml => @products }
  14. end
  15. end
  16.  
  17. def bulk_edit
  18. @products = Product.search(params[:search], params[:page])
  19.  
  20. respond_to do |format|
  21. format.html # index.html.erb
  22. format.xml { render :xml => @products }
  23. end
  24. end
  25.  
  26. # GET /products/1
  27. # GET /products/1.xml
  28. def show
  29. @product = Product.find(params[:id])
  30.  
  31. respond_to do |format|
  32. format.html # show.html.erb
  33. format.xml { render :xml => @product }
  34. end
  35. end
  36.  
  37. # GET /products/new
  38. # GET /products/new.xml
  39. def new
  40. @product = Product.new
  41.  
  42. respond_to do |format|
  43. format.html # new.html.erb
  44. format.xml { render :xml => @product }
  45. end
  46. end
  47.  
  48. # GET /products/1/edit
  49. def edit
  50. @product = Product.find(params[:id])
  51. end
  52.  
  53. # POST /products
  54. # POST /products.xml
  55. def create
  56. @product = Product.new(params[:product])
  57.  
  58. respond_to do |format|
  59. if @product.save
  60. flash[:notice] = 'Producto ha sido creado exitosamente.'
  61. format.html { redirect_to(@product) }
  62. format.xml { render :xml => @product, :status => :created, :location => @product }
  63. else
  64. format.html { render :action => "new" }
  65. format.xml { render :xml => @product.errors, :status => :unprocessable_entity }
  66. end
  67. end
  68. end
  69.  
  70. def bulk_update
  71. params[:products].each do |attributes|
  72. results = update_product(attributes)
  73. end
  74. end
  75. def update_product(attributes)
  76. @product = Product.find(attributes[:id])
  77. return @product.update_attributes(attributes)
  78. end
  79. # PUT /products/1
  80. # PUT /products/1.xml
  81. def mydebug(value, name)
  82. puts "-------------" + name + "----------------"
  83. puts value.inspect
  84. puts "-------------end of " + name + "----------------"
  85. end
  86. def update
  87. #mydebug(params[:products],'params[:products]' )
  88. #mydebug(params[:products]["1"],'params[:products][1]')
  89. #mydebug(params[:products]["1"][:id],'params[:products][1][:id]')
  90. #mydebug(params[:products]["2"][:id],'params[:products][2][:id]')
  91. #mydebug(Product.find(1),'Product.find(1)')
  92. params[:products].each do |product|
  93. #param.each do |product|
  94. #mydebug(product,'product')
  95. #mydebug(product.index,'product.index')
  96. #mydebug(product[0],'product[0]')
  97. #mydebug(product[1],'product[1]')
  98. #mydebug(product[1][:id],'product[1][:id]')
  99. @product = Product.find(product[1][:id])
  100. #mydebug(@product,'@product')
  101. if @product.update_attributes(product[1])
  102. flash[:notice] = 'Producto ha sido actualizado exitosamente.'
  103. end
  104. #end
  105. end
  106. redirect_to(products_url)
  107. #else
  108. # @product = Product.find(params[:id])
  109. # results = @product.update_attributes(params[:product])
  110. #end
  111. #respond_to do |format|
  112. # if results
  113. # flash[:notice] = 'Product was successfully updated.'
  114. # format.html { redirect_to(@product) }
  115. # format.xml { head :ok }
  116. # else
  117. # format.html { render :action => "edit" }
  118. # format.xml { render :xml => @product.errors, :status => :unprocessable_entity }
  119. # end
  120. #end
  121. end
  122.  
  123. # DELETE /products/1
  124. # DELETE /products/1.xml
  125. def destroy
  126. @product = Product.find(params[:id])
  127. @product.destroy
  128.  
  129. respond_to do |format|
  130. format.html { redirect_to(products_url) }
  131. format.xml { head :ok }
  132. end
  133. end
  134. end
Add Comment
Please, Sign In to add comment