lib/ensurance.rb in ensurance-0.1.10 vs lib/ensurance.rb in ensurance-0.1.11
- old
+ new
@@ -37,10 +37,14 @@
value = thing
if thing.is_a?(Hash)
value = thing.fetch(ensure_field.to_sym, nil) || thing.fetch(ensure_field.to_s, nil)
end
if ensure_field.to_sym == :id
- record = find(value)
+ begin
+ record = find(value)
+ rescue ActiveRecord::RecordNotFound
+ nil
+ end
else
record = find_by(ensure_field => value) if value.present? && !value.is_a?(Hash)
end
break if record.is_a?(self)
end