I was following this tutorial that shows you how to sort an array. My action looked like this:
def index
@articles = NodeType.find(1).nodes + NodeType.find(2).nodes
@articles.sort_by { |article| article.updated_at }
end
But that didn't work! It wasn't sorting at all.. at least as far as I could tell. Strange, because this worked:
def index
@articles = NodeType.find(1).nodes + NodeType.find(2).nodes
@articles = @articles.sort_by { |article| article.updated_at }
end
It seems you have to assign it to an object first, before returning it.
Showing posts with label enumerable. Show all posts
Showing posts with label enumerable. Show all posts
Tuesday, January 22, 2008
Subscribe to:
Posts (Atom)