Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ProductsController < ApplicationController
- # GET /products
- # GET /products.xml
- #before_filter :login_required
- before_filter {privilege_required('sales')}
- def index
- #@products = Product.find(:all)
- @products = Product.search(params[:search], params[:page])
- respond_to do |format|
- format.html # index.html.erb
- format.xml { render :xml => @products }
- end
- end
- def bulk_edit
- @products = Product.search(params[:search], params[:page])
- respond_to do |format|
- format.html # index.html.erb
- format.xml { render :xml => @products }
- end
- end
- # GET /products/1
- # GET /products/1.xml
- def show
- @product = Product.find(params[:id])
- respond_to do |format|
- format.html # show.html.erb
- format.xml { render :xml => @product }
- end
- end
- # GET /products/new
- # GET /products/new.xml
- def new
- @product = Product.new
- respond_to do |format|
- format.html # new.html.erb
- format.xml { render :xml => @product }
- end
- end
- # GET /products/1/edit
- def edit
- @product = Product.find(params[:id])
- end
- # POST /products
- # POST /products.xml
- def create
- @product = Product.new(params[:product])
- respond_to do |format|
- if @product.save
- flash[:notice] = 'Producto ha sido creado exitosamente.'
- format.html { redirect_to(@product) }
- format.xml { render :xml => @product, :status => :created, :location => @product }
- else
- format.html { render :action => "new" }
- format.xml { render :xml => @product.errors, :status => :unprocessable_entity }
- end
- end
- end
- def bulk_update
- params[:products].each do |attributes|
- results = update_product(attributes)
- end
- end
- def update_product(attributes)
- @product = Product.find(attributes[:id])
- return @product.update_attributes(attributes)
- end
- # PUT /products/1
- # PUT /products/1.xml
- def mydebug(value, name)
- puts "-------------" + name + "----------------"
- puts value.inspect
- puts "-------------end of " + name + "----------------"
- end
- def update
- #mydebug(params[:products],'params[:products]' )
- #mydebug(params[:products]["1"],'params[:products][1]')
- #mydebug(params[:products]["1"][:id],'params[:products][1][:id]')
- #mydebug(params[:products]["2"][:id],'params[:products][2][:id]')
- #mydebug(Product.find(1),'Product.find(1)')
- params[:products].each do |product|
- #param.each do |product|
- #mydebug(product,'product')
- #mydebug(product.index,'product.index')
- #mydebug(product[0],'product[0]')
- #mydebug(product[1],'product[1]')
- #mydebug(product[1][:id],'product[1][:id]')
- @product = Product.find(product[1][:id])
- #mydebug(@product,'@product')
- if @product.update_attributes(product[1])
- flash[:notice] = 'Producto ha sido actualizado exitosamente.'
- end
- #end
- end
- redirect_to(products_url)
- #else
- # @product = Product.find(params[:id])
- # results = @product.update_attributes(params[:product])
- #end
- #respond_to do |format|
- # if results
- # flash[:notice] = 'Product was successfully updated.'
- # format.html { redirect_to(@product) }
- # format.xml { head :ok }
- # else
- # format.html { render :action => "edit" }
- # format.xml { render :xml => @product.errors, :status => :unprocessable_entity }
- # end
- #end
- end
- # DELETE /products/1
- # DELETE /products/1.xml
- def destroy
- @product = Product.find(params[:id])
- @product.destroy
- respond_to do |format|
- format.html { redirect_to(products_url) }
- format.xml { head :ok }
- end
- end
- end
Add Comment
Please, Sign In to add comment