订购多态评论

时间:2011-07-08 16:39:41

标签: ruby-on-rails-3 polymorphism

共享/ _comments.html.haml

#comments
  - commentable.comments.each do |comment|
    = link_to image_tag(avatar_url comment.user_id,36), :controller => 'users', :action => 'show', :id => comment.user_id
    = comment.content
    %br

如何通过'created_at DESC'订购多态注释?

1 个答案:

答案 0 :(得分:1)

在你的模特中:

scope :by_created_at, order('created_at DESC')

然后在你看来:

- commentable.comments.by_created_at.each do |comment|