Class: EducodeSales::PlacesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/educode_sales/places_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate_admin, #authenticate_request, #current_user, #render_failure, #render_success

Instance Method Details

#createObject



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/educode_sales/places_controller.rb', line 31

def create
  place = @current_admin.places.new(name: params[:name])
  commons = []
  params[:area_ids].each do |d|
    commons << Common.find(d)
  end
  place.areas = commons
  if place.save
    render_success
  else
    render_failure place
  end
end

#destroyObject



60
61
62
63
64
65
66
# File 'app/controllers/educode_sales/places_controller.rb', line 60

def destroy
  place = Place.find(params[:id])
  place.destroy
  render_success
rescue ActiveRecord::DeleteRestrictionError => e
  render_failure '渠道下已有关联数据产生,暂不能删除'
end

#editObject



24
25
26
27
28
29
# File 'app/controllers/educode_sales/places_controller.rb', line 24

def edit
  @place = Place.find(params[:id])
  gon.area_ids = @place.area_ids
  gon.areas = Common.where(clazz: 'area').map { |d| { value: d.id, title: d.name } } #.unshift({value: -1, title: '全国'})
  render layout: false
end

#indexObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/educode_sales/places_controller.rb', line 5

def index
  respond_to do |format|
    authorize! :read, Place
    format.html do
    end
    format.json do
      @places = Place.page(params[:page]).per(params[:limit])
      @x = Common.find_by(clazz: '商机类型', name: 'X类')&.id
      @stage_ids = Common.where(clazz: '商机阶段', name: ['已中标','已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
    end
  end
end

#newObject



18
19
20
21
22
# File 'app/controllers/educode_sales/places_controller.rb', line 18

def new
  # gon.area_ids = @place.area_ids
  gon.areas = Common.where(clazz: 'area').map { |d| { value: d.id, title: d.name } } #.unshift({value: -1, title: '全国'})
  render layout: false
end

#updateObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/educode_sales/places_controller.rb', line 45

def update
  place = Place.find(params[:id])
  place.assign_attributes(name: params[:name])
  commons = []
  params[:area_ids].each do |d|
    commons << Common.find(d)
  end
  place.areas = commons
  if place.save
    render_success
  else
    render_failure place
  end
end