开发者

Order polymorphic comments

开发者 https://www.devze.com 2023-03-18 02:55 出处:网络
shared/_comments.html.haml #comments - commentable.comments.each do |comment| = link_to image_t开发者_如何学Cag(avatar_url comment.user_id,36), :controller => \'users\', :action => \'show\', :i

shared/_comments.html.haml

#comments
  - commentable.comments.each do |comment|
    = link_to image_t开发者_如何学Cag(avatar_url comment.user_id,36), :controller => 'users', :action => 'show', :id => comment.user_id
    = comment.content
    %br

How to order polymorphic comments by 'created_at DESC' ?


In your model:

scope :by_created_at, order('created_at DESC')

Then in your view:

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

精彩评论

暂无评论...
验证码 换一张
取 消