Sha256: b0d2f4e4d6b11782d101495689df621730007b314ad00594663fc52172eaf711

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 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.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

1 entries across 1 versions & 1 rubygems

Version Path
educode_sales-0.1.0 app/controllers/educode_sales/activities_controller.rb