# Changing accessor list order

**URL:** <https://www.ruby-forum.com/t/changing-accessor-list-order/55821>\
**Category:** Rails\
**Created:** [March 24, 2006, 1:40am UTC](https://www.ruby-forum.com/t/changing-accessor-list-order/55821 "2006-03-24T01:40:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sweatje](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@sweatje](https://www.ruby-forum.com/u/sweatje)\
**Post date:** [March 24, 2006, 1:40am UTC](https://www.ruby-forum.com/t/changing-accessor-list-order/55821/1 "2006-03-24T01:40:59Z")

</div>

Ok, I’m pretty new to Rails and I’m building a bug tracker as my first  
real project. I have a situation where a bug can have multiple comments.  
Pretty simple. When I show the comments on the screen, I want to make  
sure that they’re displayed in reverse order by date created. I have  
used the following to change the order of @bug.comments:

class Bug \< ActiveRecord::Base  
belongs\_to :priority  
has\_many :comments  
validates\_presence\_of :description, :priority

def comments  
Comment.find :all, :order =\> ‘created\_at DESC’  
end  
end

It works like a charm. But, is there a better way to do this? Should I  
be returning it as-is and reversing it in the view instead?

---

<div class="post-metadata">

**Author:** ![sweatje](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@sweatje](https://www.ruby-forum.com/u/sweatje)\
**Post date:** [March 24, 2006, 1:44am UTC](https://www.ruby-forum.com/t/changing-accessor-list-order/55821/2 "2006-03-24T01:44:06Z")

</div>

Ok, I think I already solved my own problem. Array.reverse\_each. So  
many fantastic tricks that I still have yet to learn!

---

<div class="post-metadata">

**Author:** ![sweatje](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@sweatje](https://www.ruby-forum.com/u/sweatje)\
**Post date:** [March 24, 2006, 1:44am UTC](https://www.ruby-forum.com/t/changing-accessor-list-order/55821/3 "2006-03-24T01:44:57Z")

</div>

Oops, too vague. To clarify, I removed the accessor override and just  
performed an Array.reverse\_each in the view to list comments in reverse  
order.

---

<div class="post-metadata">

**Author:** ![sweatje](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@sweatje](https://www.ruby-forum.com/u/sweatje)\
**Post date:** [March 24, 2006, 2:00am UTC](https://www.ruby-forum.com/t/changing-accessor-list-order/55821/4 "2006-03-24T02:00:19Z")

</div>

See also the :order option for has\_many relationships.

–  
– Tom M.

---

<div class="post-metadata">

**Author:** ![sweatje](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@sweatje](https://www.ruby-forum.com/u/sweatje)\
**Post date:** [March 24, 2006, 5:57am UTC](https://www.ruby-forum.com/t/changing-accessor-list-order/55821/5 "2006-03-24T05:57:17Z")

</div>

That’s even better. I didn’t realize there were so many options for  
has\_many. Thx Tom.
