I've come across this code:
def self.search(search)
if search
where(['title LIKE ? OR description LIKE ? ', "%#{search}%", "%#{search}%"])
else
scoped
end
end
What does the "scoped" statement refer to? It's surprisingly hard to Google.
I think the essence of the above snippet is: "if a search parameter is provided, create an ActiveRecord query that restricts the records returned. Otherwise, return a blank slate query." So "scoped" is a (weirdly named) object that represents a query that can be further refined before being eventually executed.
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.