Sha256: 1925b3cf1640e2ca2bd376dcf58e28860b2ea7d53dd46c8e3528f5249024bd89

Contents?: true

Size: 1.7 KB

Versions: 39

Compression:

Stored size: 1.7 KB

Contents

class Manage::BusListsController < Manage::ApplicationController
  before_action :set_bus_list, only: [:show, :edit, :update, :destroy, :toggle_bus_captain, :send_update_email]

  respond_to :html

  def index
    @bus_lists = BusList.all
    respond_with(:manage, @bus_lists)
  end

  def show
    respond_with(:manage, @bus_list)
  end

  def new
    @bus_list = BusList.new
    respond_with(:manage, @bus_list)
  end

  def edit
  end

  def create
    @bus_list = BusList.new(bus_list_params)
    @bus_list.save
    respond_with(:manage, @bus_list)
  end

  def update
    @bus_list.update_attributes(bus_list_params)
    respond_with(:manage, @bus_list)
  end

  def destroy
    School.where(bus_list_id: @bus_list.id).each do |school|
      school.questionnaires.where(riding_bus: true).map { |q| q.update_attribute(:riding_bus, false) }
      school.update_attribute(:bus_list_id, nil)
    end
    @bus_list.destroy
    respond_with(:manage, @bus_list)
  end

  def toggle_bus_captain
    @questionnaire = Questionnaire.find(params[:questionnaire_id])
    is_bus_captain = params[:bus_captain] == "1"
    @questionnaire.update_attribute(:is_bus_captain, is_bus_captain)
    if @questionnaire.reload.is_bus_captain
      Mailer.delay.bus_captain_confirmation_email(@bus_list.id, @questionnaire.user.id)
    end
    redirect_to [:manage, @bus_list]
  end

  def send_update_email
    @bus_list.passengers.each do |passenger|
      Mailer.delay.bus_list_update_email(passenger.id)
    end
    redirect_to [:manage, @bus_list]
  end

  private

  def bus_list_params
    params.require(:bus_list).permit(
      :name, :capacity, :notes, :needs_bus_captain
    )
  end

  def set_bus_list
    @bus_list = BusList.find(params[:id])
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
hackathon_manager-0.5.7 app/controllers/manage/bus_lists_controller.rb
hackathon_manager-0.5.6 app/controllers/manage/bus_lists_controller.rb
hackathon_manager-0.5.5 app/controllers/manage/bus_lists_controller.rb
hackathon_manager-0.5.4 app/controllers/manage/bus_lists_controller.rb
hackathon_manager-0.5.3 app/controllers/manage/bus_lists_controller.rb
hackathon_manager-0.5.2 app/controllers/manage/bus_lists_controller.rb
hackathon_manager-0.5.1 app/controllers/manage/bus_lists_controller.rb
hackathon_manager-0.5.0 app/controllers/manage/bus_lists_controller.rb
hackathon_manager-0.4.4 app/controllers/manage/bus_lists_controller.rb
hackathon_manager-0.4.3 app/controllers/manage/bus_lists_controller.rb
hackathon_manager-0.4.2 app/controllers/manage/bus_lists_controller.rb
hackathon_manager-0.4.1 app/controllers/manage/bus_lists_controller.rb
hackathon_manager-0.4.0 app/controllers/manage/bus_lists_controller.rb
hackathon_manager-0.3.3 app/controllers/manage/bus_lists_controller.rb
hackathon_manager-0.3.2 app/controllers/manage/bus_lists_controller.rb
hackathon_manager-0.3.1 app/controllers/manage/bus_lists_controller.rb
hackathon_manager-0.3.0 app/controllers/manage/bus_lists_controller.rb
hackathon_manager-0.2.0 app/controllers/manage/bus_lists_controller.rb
hackathon_manager-0.1.0 app/controllers/manage/bus_lists_controller.rb