内排序散列我有返回下列阵列的数据模型:红宝石具有麻烦阵列
[[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