I use this bit of code to search for records using the the like query. Is it possible to create another scope wh开发者_如何转开发ich can update a record.
scope :search, lambda{|query| where(["name LIKE ?", "%#{query}%"])}
You can use rails' update_all
method. See here for a description: http://apidock.com/rails/ActiveRecord/Relation/update_all
EDIT: It's part of the Relation class, so you may call this on scopes (It doesn't say that explicit in the documentation)
EDIT2: It works very much like destroy_all
which may also be called on scopes (Relation)
精彩评论