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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
oops, I needed to do self.primary_key = ''something'' On Jun 16, 11:43 am, Jedrin <jrubia...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
oops, I needed to do self.primary_key = ''something'' On Jun 16, 11:43 am, Jedrin <jrubia...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.