I assumed that your model name is a model - just replace it with your real model name when you execute the actual request:
Model.where("name LIKE ? OR last_name LIKE ? OR first_name LIKE ?", "%#{search}%","%#{search}%","%#{search}%")
About your worries about SQL injection - both pieces of code are immune to SQL injection. As long as you don't embed strings directly in your WHERE clause, you're fine. An example for an injectable code would be:
Model.where("name LIKE '#{params[:name]}'")
source share