More idiomatic approach to finding drafts

This commit is contained in:
Thomas Cioppettini 2014-03-25 15:56:21 -07:00
parent 86244e3a4b
commit 2beaeed36d

View file

@ -29,10 +29,12 @@ class Draft < ActiveRecord::Base
protected
def self.find_draft(user,key)
user_id = user
user_id = user.id if User === user
Draft.where(user_id: user_id, draft_key: key).first
def self.find_draft(user, key)
if user.is_a?(User)
find_by(user_id: user.id, draft_key: key)
else
find_by(user_id: user, draft_key: key)
end
end
end