From 0b157f8ded03ef988308a135e12c9bc99a1cc703 Mon Sep 17 00:00:00 2001 From: Prem Sichanugrist Date: Tue, 21 Feb 2017 19:59:56 +0900 Subject: Fix `define_attribute_method` with Symbol in AR This issue is only appear when you try to call `define_attribute_method` and passing a symbol in Active Record. It does not appear in isolation in Active Model itself. Before this patch, when you run `User.define_attribute_method :foo`, you will get: NoMethodError: undefined method `unpack' for :foo:Symbol from activerecord/lib/active_record/attribute_methods/read.rb:28:in `define_method_attribute' from activerecord/lib/active_record/attribute_methods/primary_key.rb:61:in `define_method_attribute' from activemodel/lib/active_model/attribute_methods.rb:292:in `block in define_attribute_method' from activemodel/lib/active_model/attribute_methods.rb:285:in `each' from activemodel/lib/active_model/attribute_methods.rb:285:in `define_attribute_method' This patch contains both a fix in Active Model and a test in Active Record for this error. --- activemodel/lib/active_model/attribute_methods.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activemodel/lib/active_model/attribute_methods.rb') diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb index 09825cf861..166c6ac21f 100644 --- a/activemodel/lib/active_model/attribute_methods.rb +++ b/activemodel/lib/active_model/attribute_methods.rb @@ -289,7 +289,7 @@ module ActiveModel generate_method = "define_method_#{matcher.method_missing_target}" if respond_to?(generate_method, true) - send(generate_method, attr_name) + send(generate_method, attr_name.to_s) else define_proxy_call true, generated_attribute_methods, method_name, matcher.method_missing_target, attr_name.to_s end -- cgit v1.2.3