Skip to content

Instantly share code, notes, and snippets.

@califa
Created May 9, 2011 06:44
Show Gist options
  • Save califa/962163 to your computer and use it in GitHub Desktop.
Save califa/962163 to your computer and use it in GitHub Desktop.
Controller with date method
class Event < Struct.new(:class, :name, :date); end
class StudentsController < ApplicationController
require 'table_builder'
require 'table_builder/calendar_helper'
layout 'dashboard'
def index
@student = Student.find(session[:user_id])
@date = Time.now
get_tasks
end
def get_tasks
@tasks = []
@student.courses.each do |course|
course.assignments.each do |assignment|
@tasks << Event.new(course.name, assignment.title, assignment.due_date)
end
end
end
def human_date(date)
string = ""
level = 3
now = Time.now
if date < now
string = "Overdue!"
end
if date < now + 2.days
level = 1
end
if date < now + 5.days
level = 2
end
if date < now.end_of_week
string = "This #{date.strftime('%A')}"
end
if date < now.end_of_week.next_week
string = "Next #{date.strftime('%A')}"
end
[string, level]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment