I use this bit of code to search for records using the the like query. Is it possible to create another scope which can update a record.
scope :search, lambda{|query| where(["name LIKE ?", "%#{query}%"])}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use rails’
update_allmethod. See here for a description: http://apidock.com/rails/ActiveRecord/Relation/update_allEDIT: 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_allwhich may also be called on scopes (Relation)