Add search to post list

This commit is contained in:
riggraz
2019-09-05 17:11:07 +02:00
parent a57cdc0c05
commit 3c3c14b04e
5 changed files with 58 additions and 8 deletions

View File

@@ -6,4 +6,10 @@ class Post < ApplicationRecord
validates :title, presence: true, length: { in: 4..64 }
paginates_per 15
def self.search(s = '')
s = s || ''
s = sanitize_sql_like(s)
where("posts.title ILIKE ? OR posts.description ILIKE ?", "%#{s}%", "%#{s}%")
end
end