Avoiding repeated query variables
If you find yourself wanting to dry up a query like this:
Book.where('title = ? OR author = ? OR genre = ? OR subject = ? OR keyword = ?', search_term, search_term, search_term, search_term, search_term)
use named bind variables:
Book.where('title = :s OR author = :s OR genre = :s OR subject = :s OR keyword = :s', {s: search_term})
Written by Amy Lai
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#