I'm using acts-as-taggable-on to allow my NewsItem and MediaItem models to be tagged. By default, accessing the model's tags using either tag_list
for an array of the tag names or directly via an association using tags
for collection of ActsAsTaggableOn::Tag
s, results in the tags in an arbitrary order. I would like them to always be alphabetised. There is no mention in the documentation of setting up a default order, other than a way of maintaining the order the tags were created in (by using acts_as_ordered_taggable
in the model).
Obviously I can order them every time I call tags
using news_item.tags.order(:name)
, but I would like this to be the default behaviour throughout the application and don't want to duplicate the ordering wherever I need to use tags.
How can I set up my model so that its tags
association always returns its tags in alphabetical order?