# Sort Categories by name

**URL:** <https://meta.discourse.org/t/sort-categories-by-name/62764>\
**Category:** Development\
**Created:** [15 مايو 2017، 11:47م UTC](https://meta.discourse.org/t/sort-categories-by-name/62764 "2017-05-15T23:47:35Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [15 مايو 2017، 11:47م UTC](https://meta.discourse.org/t/sort-categories-by-name/62764/1 "2017-05-15T23:47:35Z")

</div>

I need to sort all of the subcategories in a category by name.

Something like

```plaintext
cats = Category.find_by_sql("select * from categories where name like '%whatever%')
x=0
cats.sort_by_name.each do |c|
   x += 1
   c.position = x
end

```

is there some Discourse way or should I just be asking at StackOverflow?

---

_[View the full topic](https://meta.discourse.org/t/sort-categories-by-name/62764)._
