@news = Article.where(text: 'example').order(:created_at).limit(4)
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) }
Code Example |
---|
Ruby :: ruby array to string with commas |
Ruby :: ruby connect database |
Ruby :: is there a way of changing the key of a hash |
Ruby :: edit file terminal mac24 |
Ruby :: rails crud |
Ruby :: list ruby versions |
Ruby :: ruby if |
Ruby :: new date ruby |
Ruby :: how to make a new array ruby |
Ruby :: ruby extract number from string |
Ruby :: Rails.root |
Ruby :: rails rescue puts error |
Ruby :: how to update a field on after_save rails |
Ruby :: ruby hash delete |
Ruby :: heroku run rails |
Ruby :: rails devise valid_password |
Ruby :: will_paginate gem rails |
Ruby :: ruby for |
Ruby :: Ruby Regular Expressions |
Ruby :: ruby includes |
Ruby :: ruby in array |
Ruby :: ||= ruby |
Ruby :: Error occurred while parsing request parameters. |
Ruby :: ruby find by multiple columns |
Ruby :: common functions in rails |
Ruby :: ruby global property from object |
Ruby :: ruby string interpolation lazy evaluation |
Ruby :: division in ruby |
R :: R sort matrix |
R :: extract r squared from lm in r |