Class: Admin::GeoZonesController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/admin/geo_zones_controller.rb

Overview

This Controller Manage GeoZones

Instance Method Summary collapse

Instance Method Details

#add_elementObject



29
30
31
# File 'app/controllers/admin/geo_zones_controller.rb', line 29

def add_element
  render :text => @geo_zone.update_attribute(:transporter_rule_ids, @geo_zone.transporter_rule_ids << params[:element_id].to_i)
end

#createObject

Create a GeoZone

Params

  • geo_zone = Hash of GeoZone’s attributes

The GeoZone can be a child of another GeoZone.



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

def create
  if @geo_zone.save
    flash[:notice] = I18n.t('geo_zone.create.success').capitalize
  else
    flash[:error] = I18n.t('geo_zone.create.failed').capitalize
  end
  render :action => 'new', :layout => false
end

#destroyObject

Destroy a GeoZone

Params

  • id = ProductGeoZone’s id

Output

if destroy succed, return the GeoZones list


56
57
58
59
60
61
62
# File 'app/controllers/admin/geo_zones_controller.rb', line 56

def destroy
  if @geo_zone.destroy
    flash[:notice] = I18n.t('geo_zone.destroy.success').capitalize
  else
    flash[:error] = I18n.t('geo_zone.destroy.failed').capitalize
  end
end

#editObject

Edit a GeoZone

Params

  • id = GeoZone’s id to edit

  • geo_zone = Hash of GeoZone’s attributes

The GeoZone can be a child of another GeoZone.



39
40
41
# File 'app/controllers/admin/geo_zones_controller.rb', line 39

def edit
  render :layout => false
end

#indexObject

List GeoZones like a Tree.



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

def index
  @geo_zones = GeoZone.find_all_by_parent_id(nil)
end

#newObject



11
12
13
# File 'app/controllers/admin/geo_zones_controller.rb', line 11

def new
  render :layout => false
end

#updateObject



43
44
45
46
47
48
49
50
# File 'app/controllers/admin/geo_zones_controller.rb', line 43

def update
  if @geo_zone.update_attributes(params[:geo_zone])
    flash[:notice] = I18n.t('geo_zone.update.success').capitalize
  else
    flash[:error] = I18n.t('geo_zone.update.failed').capitalize
  end
  render :action => 'edit', :layout => false
end