Sha256: 1f248c8ed62cd8eb2eba6551bff076fc64831dfe8b1eb81a759c4364bf72472b

Contents?: true

Size: 1.71 KB

Versions: 4

Compression:

Stored size: 1.71 KB

Contents

require_dependency "educode_sales/application_controller"

module EducodeSales
  class ActivitiesController < ApplicationController
    def index
      respond_to do |format|
        format.html do
        end
        format.json do
          @activities = Activity
          if params[:sort].present? && params[:sort][:field]
            @activities = @activities.order("#{params[:sort][:field]} #{params[:sort][:order]}")
          else
            @activities = @activities.order("created_at desc")
          end
          @activities = @activities.page(params[:page]).per(params[:per_page])
        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
      @activity = Activity.find(params[:id])
      render layout: false
    end

    def create
      activity = @current_admin.activities.new(name: params[:name], start_at: params[:start_at], days: params[:days])
      if activity.save
        render_success
      else
        render_failure activity
      end
    end

    def update
      activity = Activity.find(params[:id])
      activity.assign_attributes(name: params[:name], start_at: params[:start_at], days: params[:days])
      if activity.save
        render_success
      else
        render_failure activity
      end
    end

    def destroy
      activity = Activity.find(params[:id])
      activity.destroy
      render_success
    rescue ActiveRecord::DeleteRestrictionError => e
      render_failure '该活动已有数据产生,暂不能删除'
    end

    def show_teachers
      render layout: false
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
educode_sales-0.1.4 app/controllers/educode_sales/activities_controller.rb
educode_sales-0.1.3 app/controllers/educode_sales/activities_controller.rb
educode_sales-0.1.2 app/controllers/educode_sales/activities_controller.rb
educode_sales-0.1.1 app/controllers/educode_sales/activities_controller.rb