內排序散列我有返回下列陣列的數據模型:紅寶石具有麻煩陣列
[[54993, {:posted_at=>1363066554, :item_id=>55007,..}],..]
的54993
是POST_ID。我正在嘗試使用這個數組並按posted_at
排序。該數組通過posted_at
正確排序。這裏是我當前的代碼:
post_ids = UserFeed.new(current_user.id).posts.collect{|x| x[0]}
posts = Post.where(:id => post_ids)
這由post_id
,不posted_at
進行排序。我試圖弄清楚如何按posted_at
排序,並想知道爲什麼數組假設post_id
。
是這個了activerecord ?無論如何,都要相應地標記它。如果是這樣,我不明白「帖子」關聯如何返回對。在AR中,當關聯配置正確時,您可以編寫'posts = UserFeed.new(current_user.id).posts.order(「posted_at ASC」)' – tokland 2013-03-12 21:56:56