In my ruby(1.9.3) on rails (3.1) app I’m trying to set some conditional behavior with respect to tasks and deadlines. Specifically the coloring of a progress bar.
Tasks belongs_to list
List has_many tasks
I’m essentialy trying to see if the last task.planned_for date in @list.tasks is past @list.deadline.
Both list.deadline and task.planned_for are :date types.
So in my view I’m looking for something like:
- if @last_task.planned_for > @list.deadline
Where
@tasks = @list.tasks.todo
@last_task = @tasks.last
Any ideas on how to best do this. This (obviously) isn’t working.
Your
@tasks.lastdoesn’t grab the latest one, it grabs the last one in the database, not in any particular order. You probably want to get it with(by ordering it descending, the first date is latest)