Class: Admin::Atreides::ProductsController

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

Instance Method Summary collapse

Instance Method Details

#newObject



3
4
5
6
7
8
9
10
# File 'app/controllers/admin/atreides/products_controller.rb', line 3

def new
  # Create post!
  resource.save!
  resource.state = :published
  super do |wants|
    wants.html { render "edit" }
  end
end

#showObject



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

def show
  super do |wants|
    wants.html { redirect_to edit_admin_product_path(resource) }
  end
end

#updateObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/admin/atreides/products_controller.rb', line 18

def update
  # Set display_order
  if params[:product].key?(:sizes_attributes)
    i = 0
    params[:product][:sizes_attributes].each{|s| s[:display_order] = (i+=1) }
  end

  # Set product price
  params[:product][:price] = params[:product][:price].to_money

  # Mark as destroyed if not included in the list
  resource.sizes.each do |s|
    unless params[:product][:sizes_attributes].map(&:id).include?(s.id)
      params[:product][:sizes_attributes] << {:id => s.id, :_destroy => true}
    end
  end
end