Sha256: 84ba3c4d84984fdb1355ef45e227a522ddaf2331f9edd687fe66eefc68ae9a68

Contents?: true

Size: 1.69 KB

Versions: 1

Compression:

Stored size: 1.69 KB

Contents

module Applicants
  class Spike::ApplicantsController < Applicants::ApplicationController
    http_basic_authenticate_with name: "usertesting", password: "usertesting", except: [:update]
    before_filter :set_applicant

    respond_to :html, :json

    layout "applicants/spike"

    def index
      if params[:q]
        @applicants = Applicants::Applicant.where(params[:q].delete_if {|k, v| v.blank?})
      else
        offset = params[:offset] || 0
        limit  = params[:limit]  || 100
        state  = params[:state]  || 'reviewable'
        applicants_of_state = Applicants::Applicant.with_state(state)

        @applicants  = if state == 'reviewable'
                         applicants_of_state.offset(offset).limit(limit).order('updated_at ASC')
                        else
                         applicants_of_state.offset(offset).limit(limit).order('updated_at DESC')
                        end
        @total       = applicants_of_state.count
        @stale_count = applicants_of_state.stale.count
      end
    end

    def show
    end

    def update
      @applicant.update_attributes params[:applicant]
      respond_to do |format|
        format.html { redirect_to spike_root_path, notice: "Applicant updated!" }
      end
    end

    def event
      @applicant.update_attributes({ event: params[:event] }) if params[:event]
      respond_to do |format|
        format.html { redirect_to spike_root_path, notice: "Applicant updated!" }
        format.json { head :ok }
      end
    end

    def destroy
      @applicant.disable!
      head :ok
    end

  private

    def set_applicant
      if params.has_key? :id
        @applicant = Applicants::Applicant.find params[:id]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
applicants-0.11.0 app/controllers/applicants/spike/applicants_controller.rb