简体   繁体   中英

In Ruby, what does “scoped” mean?

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.

http://guides.rubyonrails.org/active_record_querying.html

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM