mirror of
https://github.com/astuto/astuto.git
synced 2025-12-15 03:07:52 +01:00
Add sort by filter to post list (#271)
This commit is contained in:
committed by
GitHub
parent
fadd577db8
commit
9c5553cc32
@@ -25,5 +25,20 @@ class Post < ApplicationRecord
|
||||
s = sanitize_sql_like(s)
|
||||
where("posts.title ILIKE ? OR posts.description ILIKE ?", "%#{s}%", "%#{s}%")
|
||||
end
|
||||
|
||||
def order_by(sort_by)
|
||||
case sort_by
|
||||
when 'newest'
|
||||
order(created_at: :desc)
|
||||
when 'trending'
|
||||
order(hotness: :desc)
|
||||
when 'most_voted'
|
||||
order(likes_count: :desc)
|
||||
when 'oldest'
|
||||
order(created_at: :asc)
|
||||
else
|
||||
order(created_at: :desc)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user