rails8-memoapp/app/models/memo.rb

12 lines
243 B
Ruby
Raw Normal View History

2025-02-20 22:46:52 +09:00
class Memo < ApplicationRecord
validates :content, presence: true
def self.search(query)
if query.present?
where('content LIKE ?', "%#{query}%").order(created_at: :desc)
else
order(created_at: :desc)
end
end
end