Ask A Question

Notifications

You’re not receiving notifications from this thread.

How we can use Like queries for searching on encrypted data? I used default Active Record Encryption

Vishwani patlan asked in Databases

class Propose < ApplicationRecord
encrypts :email, :phone_number, :name, deterministic: true

scope :search_filter, -> (params) do
if params[:keyword].present?
where(search_filter_query, "%#{params[:keyword]}%", "%#{params[:keyword]}%", "%#{params[:keyword]}%", "%#{params[:keyword]}%", "%#{params[:keyword]}%").distinct
else
all
end
end

def self.search_filter_query
<<-SQL
proposes.email like ? or
proposes.first_name like ? or
proposes.last_name like ? or
proposes.phone_number like ?

SQL
end
end

this is my code when I send in "some text" in params[:keyword] I always get empty [] and data with that text is existing in my database.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 85,376+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.