From 675094b2757cf90399dadca4489b1036810ae570 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 5 Jan 2012 20:15:52 -0200 Subject: More 1.9 way --- activemodel/lib/active_model/conversion.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/activemodel/lib/active_model/conversion.rb b/activemodel/lib/active_model/conversion.rb index 80a3ba51c3..c7c805f1a2 100644 --- a/activemodel/lib/active_model/conversion.rb +++ b/activemodel/lib/active_model/conversion.rb @@ -39,11 +39,9 @@ module ActiveModel # Returns an Enumerable of all key attributes if any is set, regardless # if the object is persisted or not. - # - # Note the default implementation uses persisted? just because all objects - # in Ruby 1.8.x responds to :id. def to_key - persisted? ? [id] : nil + key = respond_to?(:id) && id + key ? [key] : nil end # Returns a string representing the object's key suitable for use in URLs, -- cgit v1.2.3