Skip to content

Instantly share code, notes, and snippets.

@dacur
Created September 3, 2014 15:12
Show Gist options
  • Select an option

  • Save dacur/131615e7b5b414c69e5d to your computer and use it in GitHub Desktop.

Select an option

Save dacur/131615e7b5b414c69e5d to your computer and use it in GitHub Desktop.
You have a search box where someone can enter a first OR last name. You need to search your database of all first names AND last names looking for the value entered. The code below is ActiveRecord's way of handling this search for you - no SQL required. See here for more info: http://stackoverflow.com/questions/3684311/rails-how-to-chain-scope-q…
@vendorsfound = Vendor.where("first like ? OR last like ?", "%" + params[:first] + "%", "%" + params[:first] + "%").order("LOWER(last) ASC, first")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment