Sha256: 96d59fed4406919e9cc9bdbcf28e5e0271ebada8908ff2f797525c20e5daae6f

Contents?: true

Size: 1.82 KB

Versions: 22

Compression:

Stored size: 1.82 KB

Contents

require_dependency "educode_sales/application_controller"

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

    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

    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

    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

    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

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

  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
educode_sales-0.3.8 app/controllers/educode_sales/places_controller.rb
educode_sales-0.3.7 app/controllers/educode_sales/places_controller.rb
educode_sales-0.3.6 app/controllers/educode_sales/places_controller.rb
educode_sales-0.3.5 app/controllers/educode_sales/places_controller.rb
educode_sales-0.3.4 app/controllers/educode_sales/places_controller.rb
educode_sales-0.3.3 app/controllers/educode_sales/places_controller.rb
educode_sales-0.3.2 app/controllers/educode_sales/places_controller.rb
educode_sales-0.3.1 app/controllers/educode_sales/places_controller.rb
educode_sales-0.3.0 app/controllers/educode_sales/places_controller.rb
educode_sales-0.2.9 app/controllers/educode_sales/places_controller.rb
educode_sales-0.2.8 app/controllers/educode_sales/places_controller.rb
educode_sales-0.2.7 app/controllers/educode_sales/places_controller.rb
educode_sales-0.2.6 app/controllers/educode_sales/places_controller.rb
educode_sales-0.2.5 app/controllers/educode_sales/places_controller.rb
educode_sales-0.2.4 app/controllers/educode_sales/places_controller.rb
educode_sales-0.2.3 app/controllers/educode_sales/places_controller.rb
educode_sales-0.2.2 app/controllers/educode_sales/places_controller.rb
educode_sales-0.2.1 app/controllers/educode_sales/places_controller.rb
educode_sales-0.2.0 app/controllers/educode_sales/places_controller.rb
educode_sales-0.1.8 app/controllers/educode_sales/places_controller.rb