I have a model Post
. I want to show first posts where name
is 'esa'
then order by updated_at
.
I tried this in post.rb
but doesn't work:
default_scope {Post.where(name: 'esa') && order(updated_at: :desc) }
I have a model Post
. I want to show first posts where name
is 'esa'
then order by updated_at
.
I tried this in post.rb
but doesn't work:
default_scope {Post.where(name: 'esa') && order(updated_at: :desc) }
That would be rather ugly, but here it is.
default_scope do
order("CASE WHEN name = 'esa' THEN 0 ELSE 1 END").order(updated_at: :desc)
end