Skip to content

Instantly share code, notes, and snippets.

@EminenceHC
Created November 27, 2013 18:32
Show Gist options
  • Save EminenceHC/7680797 to your computer and use it in GitHub Desktop.
Save EminenceHC/7680797 to your computer and use it in GitHub Desktop.
Module problem
module DrugAssessmentMethods
def index
@users = User.all
@users_array = User.where(loginable_type: 'Student').includes(:loginable).all.map { |u| [u.full_name, u.loginable.id] }
if current_user.loginable_type == 'Student'
@sid = current_user.loginable.id
elsif current_user.loginable_type != 'Student'
if
params[:student_id].present?
@sid = params[:student_id]
else
@sid = 0
end
end
@l = DrugAssessment.order('cweek DESC').where(student_id: @sid).search(params[:l])
@da = @l.result
@test = Array.new
@da.each do |r|
unless r.cweek.nil? or r.cweek == 0
@test.push(r.cweek)
end
end
@test = @test.uniq
@year = Date.today.cwyear
@current_cweek = Date.today.cweek
@start_cweek = 34
@emptycount = 0
while @current_cweek > @start_cweek do
if @test.include?(@current_cweek)
else
charles = DrugAssessment.new(cweek: @current_cweek)
@da << charles
@emptycount = @emptycount + 1
end
@current_cweek = @current_cweek - 1
end
@da = @da.sort_by{|a| -(a.cweek)}
end
end
class HomeController < ApplicationController
before_filter :authenticate_user!
include DrugAssessmentMethods, SurveysToBeTaken
end
module SurveysToBeTaken
def index
@today = Date.today.strftime("%m/%d/%Y")
@map_survey_ids = Survey.pluck(:id)
@map_result_ids = ResultSet.where(user_id: current_user.id).pluck(:survey_id)
@compare = @map_survey_ids - @map_result_ids
runquery = Survey
if is_student
runquery = runquery.where(privilege: [1, 3])
elsif is_counselor && is_admin == false
runquery = runquery.where(privilege:[2, 3])
elsif is_counselor && is_admin
runquery = runquery.where(privilege:[1, 2, 3])
end
runquery = runquery.select('surveys.*')
@surveys = runquery
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment