From 2beaeed36d3d51f3e66cf2b79d6b1bea4a51465e Mon Sep 17 00:00:00 2001 From: Thomas Cioppettini Date: Tue, 25 Mar 2014 15:56:21 -0700 Subject: [PATCH] More idiomatic approach to finding drafts --- app/models/draft.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/models/draft.rb b/app/models/draft.rb index 0972eb25e21..3f0527c8813 100644 --- a/app/models/draft.rb +++ b/app/models/draft.rb @@ -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