Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUBY

rails order by value

SORT_ORDER = %w[under_review submitted published]

# Rails 7
Post.in_order_of(:state, SORT_ORDER).all

# Older versions
Post.all.sort_by{ |post| SORT_ORDER.index(post.state) }
Source by rubysnippets.net #
 
PREVIOUS NEXT
Tagged: #rails #order
ADD COMMENT
Topic
Name
7+9 =