It fails because you are asking your db to do the sorting.
@posts = Post.all.sort {|a,b| a.custom_method <=> b.custom_method}
Note that this becomes non-trivial when you want to start paging results and no longer wish to fetch .all
. Think about your design a bit before you go with this.