Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class ActiveRecord::Base
def self.find_by_sample(sample)
columns = self.columns.reject {|column| %w(id created_at updated_at).include?(column.name) }
cond_str, cond_val = [], []
columns.each do |column|
value = sample.send(column.name)
next if value.nil?
cond_str << "#{column.name}=?"
cond_val << value
end
self.all(:conditions=>[cond_str.join(" and "),*cond_val])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment