Class: EducodeSales::PlacesController
Instance Method Summary
collapse
#authenticate_admin, #authenticate_request, #current_user, #filter, #is_commissioner_above?, #paginate, #render_failure, #render_success, #subject_members, #subject_staffs, #subject_url
#add_businesses_score, #base_url, #collection_amount_score, #completion_rate, #current?, #disk_filename, #get_businesses_chart, #handled_data, #handled_time_data, #handled_time_data_accurate, #relative_path, #signed_amount_score, #storage_path, #url_to_avatar, #visits_score
Instance Method Details
#create ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'app/controllers/educode_sales/places_controller.rb', line 35
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
|
#destroy ⇒ Object
64
65
66
67
68
69
70
|
# File 'app/controllers/educode_sales/places_controller.rb', line 64
def destroy
place = Place.find(params[:id])
place.destroy
render_success
rescue ActiveRecord::DeleteRestrictionError => e
render_failure '渠道下已有关联数据产生,暂不能删除'
end
|
#edit ⇒ Object
28
29
30
31
32
33
|
# File 'app/controllers/educode_sales/places_controller.rb', line 28
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 } } render layout: false
end
|
#index ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# 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 = EducodeSales::Place.all
if params[:q].present? && params[:q][:name].present?
@places = @places.where("name like ?", "%#{params[:q][:name]}%")
end
@places = @places.page(params[:page]).per(params[:limit])
@x = Common.find_by(extras: EducodeSales::Common::XTYPE)&.id
@stage_ids = Common.where(clazz: '商机阶段', name: ['已中标','已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
end
end
end
|
#new ⇒ Object
22
23
24
25
26
|
# File 'app/controllers/educode_sales/places_controller.rb', line 22
def new
gon.areas = Common.where(clazz: 'area').map { |d| { value: d.id, title: d.name } } render layout: false
end
|
#update ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'app/controllers/educode_sales/places_controller.rb', line 49
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
|