Hi *,
I''m going mad because I''m not able to implement a custom sort
on an
array of models.
The order must be by type, where type are custom strings, so Subject
> LessonPlan > Assignment > Resource and if the type is the same by
date using a datetime field (created_at).
def <=>(other)
if self["type"] == "Subject"
return +1
elsif other["type"] == "Subject"
return -1
elsif self["type"] == "LessonPlan"
return +1
elsif other["type"] == "LessonPlan"
return -1
elsif self["type"] == "Assignment"
return +1
elsif other["type"] == "Assignment"
return -1
elsif self["type"] == other["type"]
return self.created_at <=> other.created_at
end
end
The resulting array (after calling sort) is not ordered at all, on 2
Resource and 1 Assignment the Assignment is the last ...
Someone with a clue of what''s happening ? :)
TIA,
ngw
--
Nicholas Wieland
nicholas_wieland@yahoo.it
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060823/3306d830/attachment-0001.html