# Getting "undefined method \`macro'" for different classes

**URL:** <https://www.ruby-forum.com/t/getting-undefined-method-macro-for-different-classes/146985>\
**Category:** Rails\
**Created:** [August 27, 2008, 10:11am UTC](https://www.ruby-forum.com/t/getting-undefined-method-macro-for-different-classes/146985 "2008-08-27T10:11:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [August 27, 2008, 10:11am UTC](https://www.ruby-forum.com/t/getting-undefined-method-macro-for-different-classes/146985/1 "2008-08-27T10:11:50Z")

</div>

I am not sure what is causing this. As mentioned I am getting the same  
error from different classes and no where do I have a custom macro  
method.

I have reset the server a few times, but I still get the same thing.  
The code running on the live server works fine. Although I have made  
some changes, none of them are related to data access.

Any ideas?

====

One of the cases is happening on the following call:

game\_dates = GameDate.find( :all,  
:conditions =\> “season\_id =  
#{self.id}”,  
:include =\> [{:bookings =\>  
:location}])

NoMethodError (undefined method `macro' for #<GameDate:0x1eb1940>): /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/attribute_methods.rb:256:in`method\_missing’  
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active\_record/association\_preload.rb:40:in  
`preload_one_association' /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/association_preload.rb:38:in`each’  
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active\_record/association\_preload.rb:38:in  
`preload_one_association' /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/association_preload.rb:17:in`preload\_associations’  
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active\_record/association\_preload.rb:21:in  
`preload_associations' /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/association_preload.rb:19:in`each’  
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active\_record/association\_preload.rb:19:in  
`preload_associations' /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/association_preload.rb:16:in`preload\_associations’  
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active\_record/association\_preload.rb:16:in  
`each' /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/association_preload.rb:16:in`preload\_associations’  
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active\_record/base.rb:1343:in  
`find_every' /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/base.rb:536:in`find’  
/app/models/season.rb:54:in `create\_games’

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [August 27, 2008, 10:26am UTC](https://www.ruby-forum.com/t/getting-undefined-method-macro-for-different-classes/146985/2 "2008-08-27T10:26:27Z")

</div>

On 27 Aug 2008, at 09:11, Chris O. wrote:

> I am not sure what is causing this. As mentioned I am getting the  
> same  
> error from different classes and no where do I have a custom macro  
> method.
> 
> I have reset the server a few times, but I still get the same thing.  
> The code running on the live server works fine. Although I have made  
> some changes, none of them are related to data access.

> Any ideas?

What’s in your models ? I’d guess that you’ve accidentally overwritten  
an activerecord method,

Fred

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [August 27, 2008, 10:39am UTC](https://www.ruby-forum.com/t/getting-undefined-method-macro-for-different-classes/146985/3 "2008-08-27T10:39:54Z")

</div>

On Wed, Aug 27, 2008 at 10:25 AM, Frederick C. \<  
removed\_email\_address@domain.invalid\> wrote:

> What’s in your models ? I’d guess that you’ve accidentally overwritten  
> an activerecord method,

Particularly in the Season model and its method create\_games  
as indicated at the bottom of the errors:

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [August 27, 2008, 11:27am UTC](https://www.ruby-forum.com/t/getting-undefined-method-macro-for-different-classes/146985/4 "2008-08-27T11:27:58Z")

</div>

shouldnt it be

:conditions =\> [“season\_id = ?”, id]

or

:conditions =\> {:season\_id =\> self},

instead of

:conditions =\> “season\_id =#{self.id}”,

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [August 27, 2008, 4:57pm UTC](https://www.ruby-forum.com/t/getting-undefined-method-macro-for-different-classes/146985/5 "2008-08-27T16:57:46Z")

</div>

Thx Fred!

On Aug 27, 10:45 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [August 27, 2008, 11:46am UTC](https://www.ruby-forum.com/t/getting-undefined-method-macro-for-different-classes/146985/6 "2008-08-27T11:46:10Z")

</div>

On 27 Aug 2008, at 10:27, Wolas! wrote:

> :conditions =\> “season\_id =#{self.id}”,

All three will work. the latter opens a window for injection nastiness.

Fred

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [August 27, 2008, 6:00pm UTC](https://www.ruby-forum.com/t/getting-undefined-method-macro-for-different-classes/146985/7 "2008-08-27T18:00:34Z")

</div>

On 27 Aug 2008, at 16:43, Chris O. wrote:

> > > 
> > 
> > Particularly in the Season model and its method create\_games  
> > as indicated at the bottom of the errors:
> 
> It turns out the error is in a couple of custom method I added to the  
> Array class, although I am not sure where the overlap is.
> 
> These are the methods I added to lib/array.rb.

There is already a method group\_by in rails, you’ve overwritten it  
with one which different meaning

rails: \>\> [1,2,3,‘Foo’, ‘Boo’].group\_by {|r| r.class}  
=\> [[Fixnum, [1, 2, 3]], [String, [“Foo”, “Boo”]]]

you:

[1,2,3,‘Foo’, ‘Boo’].group\_by {|r| r.class}  
=\> {“Boo”=\>[String], 1=\>[Fixnum], 2=\>[Fixnum], “Foo”=\>[String],  
3=\>[Fixnum]}

which doesn’t seem to be doing anything useful, at least not in the  
way rails uses it

Fred

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [August 27, 2008, 5:43pm UTC](https://www.ruby-forum.com/t/getting-undefined-method-macro-for-different-classes/146985/8 "2008-08-27T17:43:15Z")

</div>

Franz S. wrote:

> On Wed, Aug 27, 2008 at 10:25 AM, Frederick C. \<  
> removed\_email\_address@domain.invalid\> wrote:
> 
> > What’s in your models ? I’d guess that you’ve accidentally overwritten  
> > an activerecord method,
> 
> Particularly in the Season model and its method create\_games  
> as indicated at the bottom of the errors:

It turns out the error is in a couple of custom method I added to the  
Array class, although I am not sure where the overlap is.

These are the methods I added to lib/array.rb.

class Array  
def group  
groups = {}  
self.each do |item|  
groups[item] ||= []  
groups[item] \<\< item  
end  
groups  
end

def group\_by(&block)  
groups = {}  
self.each do |item|  
val = yield(item)  
groups[item] ||= []  
groups[item] \<\< val  
end  
groups  
end  
end

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [August 27, 2008, 7:58pm UTC](https://www.ruby-forum.com/t/getting-undefined-method-macro-for-different-classes/146985/9 "2008-08-27T19:58:31Z")

</div>

Thanks for the help Fred.
