Class: Admin::ProductsController

Inherits:
AdminController
  • Object
show all
Defined in:
app/controllers/admin/products_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/admin/products_controller.rb', line 26

def create
  respond_to do |format|
    format.html do
      @product = Product.new(post_params[:product])
      if @product.save
        redirect_to edit_admin_product_path(@product), notice: t(:successfully_added)
      else
        render action: 'new'
      end
    end
  end
end

#destroyObject



52
53
54
55
# File 'app/controllers/admin/products_controller.rb', line 52

def destroy
  @product.destroy
  redirect_to admin_products_url, notice: t(:successfully_deleted)
end

#editObject



20
21
22
23
24
# File 'app/controllers/admin/products_controller.rb', line 20

def edit
  @product_groups = ProductGroup.contains_product(@product)
  @product.find_or_build_all_answers
  respond_with @products
end

#indexObject



7
8
9
10
# File 'app/controllers/admin/products_controller.rb', line 7

def index
  @products = Product.order(:id)
  respond_with @products
end

#newObject



12
13
14
15
16
17
18
# File 'app/controllers/admin/products_controller.rb', line 12

def new
  @products = Product.order(:id)
  @product = Product.new
  @product.pictures.build
  @product.find_or_build_all_answers
  respond_with @product
end

#updateObject



39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/admin/products_controller.rb', line 39

def update
  respond_to do |format|
    format.html do
      @product_groups = ProductGroup.contains_product(@product)
      if @product.update_attributes(post_params[:product])
        redirect_to edit_admin_product_path(@product), notice: t(:successfully_updated)
      else
        respond_with @product
      end
    end
  end
end