Skip to content

Instantly share code, notes, and snippets.

@Sailias
Forked from onlymejosh/gist:903745
Created April 5, 2011 15:00
Show Gist options
  • Save Sailias/903773 to your computer and use it in GitHub Desktop.
Save Sailias/903773 to your computer and use it in GitHub Desktop.
def show
authorize! :assignment, :show
@assignment = Assignment.find(params[:id])
@related_logs = @assignment.assignment_logs.page(params[:page]).per(4).order('assignment_logs.date DESC').includes(:user)
# do a find to find and order candidates by there current employment
@candidates = AssignmentList.where('assignment_lists.assignment_id = ?', @assignment.id)
.joins('LEFT JOIN candidates ON assignment_lists.candidate_id = candidates.id
LEFT JOIN histories ON histories.candidate_id = candidates.id AND histories.finish_date IS null
LEFT JOIN institutions ON histories.institution_id = institutions.id')
.order('institutions.name ASC, candidates.last_name ASC')
.select('candidates.*, histories.job_title, institutions.name')
.group('candidates.id')
respond_with(@assignment)
end
@candidates = @assignment.assignment_lists.includes({:candidates=>{:histories=>:institutions}}
.where('histories.finish_date IS NULL')
.order("institutions.name, candidates.last_name)
.group('candidates.id)
for can in @candidates
puts can.last_name
puts histories.job_title
puts institutions.name
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment