I tried to create a simple search function in my app.
In the model
def self.search(search)
where("title LIKE ?", "%#{search}%") | where("description LIKE ?", "%#{search}%")
end
In controller
if params[:search]
@advertisements = Advertisement.search(params[:search]).order("created_at DESC")
I got an error "undefined method `order' for #". What should I do?
Update your search method as
def self.search(search)
where("title LIKE ? OR description LIKE ?", "%#{search}%", "%#{search}%"))
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.