I get "uninitialized constant ClassMethods" when I try this:
require "sort_order"
class Player < ActiveRecord::Base
include SortOrder::ClassMethods
tester
end
module SortOrder
module ClassMethods
def tester
@test = 2
end
end
module InstanceMethods
def testers
@test = 35
end
end
end
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:123:in
`const_missing''
#{RAILS_ROOT}/app/models/player.rb:5
#{RAILS_ROOT}/app/controllers/players_controller.rb:13:in `list''
-e:4
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:123:in
`const_missing''
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:140:in
`load''
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:56:in
`require_or_load''
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:30:in
`depend_on''
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:85:in
`require_dependency''
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:98:in
`const_missing''
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:131:in
`const_missing''
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/inflector.rb:161:in
`constantize''
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/core_ext/string/inflections.rb:59:in
`constantize''
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/pagination.rb:194:in
`paginator_and_collection_for''
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/pagination.rb:129:in
`paginate''
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:910:in
`perform_action_without_filters''
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/filters.rb:368:in
`perform_action_without_benchmark''
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/benchmarking.rb:69:in
`perform_action_without_rescue''
C:/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure''
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/benchmarking.rb:69:in
`perform_action_without_rescue''
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/rescue.rb:82:in
`perform_action''
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:381:in
`process_without_filters''
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/filters.rb:377:in
`process_without_session_management_support''
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/session_management.rb:117:in
`process''
C:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/dispatcher.rb:38:in
`dispatch''
C:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/webrick_server.rb:115:in
`handle_dispatch''
C:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/webrick_server.rb:81:in
`service''
C:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service''
C:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run''
C:/ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread''
C:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread''
C:/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start''
C:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start''
C:/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start''
C:/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start''
C:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/webrick_server.rb:67:in
`dispatch''
C:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/commands/servers/webrick.rb:59
C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
`require''
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:in
`require''
C:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/commands/server.rb:30
C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
`require''
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:in
`require''
script/server:3
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:123:in
`const_missing''
#{RAILS_ROOT}/app/models/player.rb:5
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:140:in
`load''
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:56:in
`require_or_load''
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:30:in
`depend_on''
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:85:in
`require_dependency''
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:98:in
`const_missing''
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:131:in
`const_missing''
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/inflector.rb:161:in
`constantize''
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/core_ext/string/inflections.rb:59:in
`constantize''
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/pagination.rb:194:in
`paginator_and_collection_for''
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/pagination.rb:129:in
`paginate''
#{RAILS_ROOT}/app/controllers/players_controller.rb:13:in `list''
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:910:in
`perform_action_without_filters''
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/filters.rb:368:in
`perform_action_without_benchmark''
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/benchmarking.rb:69:in
`perform_action_without_rescue''
C:/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure''
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/benchmarking.rb:69:in
`perform_action_without_rescue''
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/rescue.rb:82:in
`perform_action''
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/base.rb:381:in
`process_without_filters''
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/filters.rb:377:in
`process_without_session_management_support''
C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.1/lib/action_controller/session_management.rb:117:in
`process''
C:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/dispatcher.rb:38:in
`dispatch''
C:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/webrick_server.rb:115:in
`handle_dispatch''
C:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/webrick_server.rb:81:in
`service''
C:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service''
C:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run''
C:/ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread''
C:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread''
C:/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start''
C:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start''
C:/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start''
C:/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start''
C:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/webrick_server.rb:67:in
`dispatch''
C:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/commands/servers/webrick.rb:59
C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
`require''
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:in
`require''
C:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.2/lib/commands/server.rb:30
C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in
`require''
C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:in
`require''
script/server:3
-e:4
This error occured while loading the following files:
player.rb
sort_order/class_methods.rb
So, why does it try for a secondary file?
On 5/18/06, Chris T <ctmailinglists@googlemail.com>
wrote:>
> Thanks for this. Couldn''t make it work, but it gave me the energy
to
> give it another go, and with the help of the Pickaxe, managed to make it
> work.
>
> What I did (in case anyone else needs it) is split the module into two
> submodules, then include the submodule containing the instance methods,
> and extend [the class with] the one containing the class methods. So it
> looked like this:
> [lib/trust_ranking.rb]
> module TrustRanking
> module ClassMethods
> def shinynewclassmethod
> # stuff here
> end
>
> #more methods
> end
>
> module InstanceMethods
> def shinynewinstancemethod
> # stuff here
> end
>
> #more methods
> end
> end
>
> class User < ActiveRecord::Base
> include TrustRanking::InstanceMethods
> extend TrustRanking::ClassMethods
> #
> end
>
> Thanks again for your help.
> Chris
>
> Ross Dawson wrote:
> > Saw this
> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/35979
> >
> > so
> >
> > module Foo
> > module ClassMethods
> > def bar
> > puts ''hello from class method bar''
> > end
> > end
> >
> > include ClassMethods
> >
> > def self.append_features(klass)
> > super
> > klass.extend(ClassMethods)
> > end
> > end
> >
> > class FooBar
> > include Foo
> > end
> >
> > FooBar.bar
> >
> >
> >> hello from class method bar
> >>
> >
> > HTH
> >
> > Ross
> >
> >
> >> -----Original Message-----
> >> From: rails-bounces@lists.rubyonrails.org
> >> [mailto:rails-bounces@lists.rubyonrails.org]On Behalf Of Chris T
> >> Sent: Thursday, 18 May 2006 8:16 AM
> >> To: rails@lists.rubyonrails.org
> >> Subject: [Rails] Help mixin in class methods
> >>
> >>
> >> Starting to feel more confident and code is DRYing up nicely,
> >> but I''ve
> >> hit a brick wall here and hoping someone can help me.
> >>
> >> I''ve got a module, TrustRanking, which extends a number
of model''s
> >> instance methods, and I want to extend their class methods too,
but I
> >> can seem to work out how to do it.
> >>
> >> Simply including the module from the class works a treat for the
> >> instance methods, but not for the class methods. I''ve
tried a whole
> >> bunch of things, putting the instance methods and class methods in
> >> different submodules and calling them separately (and
> >> differently -- is
> >> it extend for the class methods?). Is anyone able to point me in
the
> >> right direction. Have tried looking at a couple of plug-ins
> >> (acts_as_taggable), but it''s not helping. Maybe
I''m just
> >> tired.. or dense.
> >>
> >> Tx
> >>
> >> _______________________________________________
> >> Rails mailing list
> >> Rails@lists.rubyonrails.org
> >> http://lists.rubyonrails.org/mailman/listinfo/rails
> >>
> >>
> > _______________________________________________
> > Rails mailing list
> > Rails@lists.rubyonrails.org
> > http://lists.rubyonrails.org/mailman/listinfo/rails
> >
> >
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
--
Jim
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060622/52acef9d/attachment-0001.html