# Class methods from module where active rec is involved

**URL:** <https://www.ruby-forum.com/t/class-methods-from-module-where-active-rec-is-involved/190219>\
**Category:** Rails\
**Created:** [June 17, 2010, 4:22pm UTC](https://www.ruby-forum.com/t/class-methods-from-module-where-active-rec-is-involved/190219 "2010-06-17T16:22:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jedrin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@Jedrin](https://www.ruby-forum.com/u/Jedrin)\
**Post date:** [June 17, 2010, 4:22pm UTC](https://www.ruby-forum.com/t/class-methods-from-module-where-active-rec-is-involved/190219/1 "2010-06-17T16:22:23Z")

</div>

I have a module as shown below and when I extend an active record to  
use it, I can not access the  
primary\_key method. In a simple test program using a similar approach  
where active record is not involved, access to the class methods seems  
to work ok. What can I do to make this work or so that I can access  
the class methods ?

##################################

require ‘active\_record’

DB\_Host = ‘localhost’  
DB\_Database = ‘proj1’  
DB\_Port = 5432

ActiveRecord::Base.establish\_connection(  
:adapter =\> “postgresql”,  
:host =\> DB\_Host,  
:database =\> DB\_Database,  
:username =\> “me”

# :password =\> “secret”

)

module ModelClassMethods

def mycreate(pkey\_val)  
pkey\_fld = self.primary\_key  
end

end

class ActiveNode \< ActiveRecord::Base  
extend ModelClassMethods

# include ModelMethods

end

---

<div class="post-metadata">

**Author:** ![Jedrin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@Jedrin](https://www.ruby-forum.com/u/Jedrin)\
**Post date:** [June 17, 2010, 4:22pm UTC](https://www.ruby-forum.com/t/class-methods-from-module-where-active-rec-is-involved/190219/2 "2010-06-17T16:22:27Z")

</div>

oops, I needed to do

self.primary\_key = ‘something’

---

<div class="post-metadata">

**Author:** ![Jedrin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@Jedrin](https://www.ruby-forum.com/u/Jedrin)\
**Post date:** [June 17, 2010, 4:22pm UTC](https://www.ruby-forum.com/t/class-methods-from-module-where-active-rec-is-involved/190219/3 "2010-06-17T16:22:36Z")

</div>

oops, I needed to do

self.primary\_key = ‘something’
