Question: I have the following. How best to refactor it:

```
  def self.search(search, organization_id, is_admin)
    if is_admin == false
      where("record_no LIKE ?", "%#{search}%").
        where("organization_id = ?", organization_id)
    else
      where("record_no LIKE ?", "%#{search}%")
    end
  end

```

Basically this means, I want it to show all records without the `organization_id` when user is an admin.

Answer: 
It can looks like this:

```
def self.search(search, organization_id, is_admin)
  criteria = where("record_no LIKE ?", "%#{search}%")
  criteria = criteria.where("organization_id = ?", organization_id) unless is_admin
  criteria
end

```
Let combine the conditions to `where`

```
def self.search(search, organization_id, is_admin)
  where("record_no LIKE ? AND (? OR organization_id = ?)", "%#{search}%", is_admin, organization_id)
end

```