Class: Admin::OptionTypesController

Inherits:
ResourceController
  • Object
show all
Defined in:
app/controllers/admin/option_types_controller.rb

Instance Method Summary collapse

Instance Method Details

#availableObject



4
5
6
7
# File 'app/controllers/admin/option_types_controller.rb', line 4

def available
  set_available_option_types
  render :layout => false
end

#removeObject



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

def remove
  @product.option_types.delete(@option_type)
  @product.save
  flash.notice = I18n.t("notice_messages.option_type_removed")
  redirect_to selected_admin_product_option_types_url(@product)
end

#selectObject

AJAX method for selecting an existing option type and associating with the current product



32
33
34
35
36
37
38
39
# File 'app/controllers/admin/option_types_controller.rb', line 32

def select
  @product = Product.find_by_param!(params[:product_id])
  product_option_type = ProductOptionType.new(:product => @product, :option_type => OptionType.find(params[:id]))
  product_option_type.save
  @product.reload
  @option_types = @product.option_types
  set_available_option_types
end

#selectedObject



9
10
11
# File 'app/controllers/admin/option_types_controller.rb', line 9

def selected
  @option_types = @product.option_types
end

#update_positionsObject



20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/admin/option_types_controller.rb', line 20

def update_positions
  params[:positions].each do |id, index|
    OptionType.update_all(['position=?', index], ['id=?', id])
  end
  
  respond_to do |format|
    format.html { redirect_to admin_product_variants_url(params[:product_id]) }
    format.js  { render :text => 'Ok' }
  end
end