Kurtis Seebaldt wrote:
>I''m trying to figure out how to use modules with my model classes.
>I''m going to have good number of model classes that don''t
map to the
>database, and I''d like to put some of these in seperate modules.
I''ve
>been wrestling with this for 2 days and can''t figure out how to get
it
>to work. Rails seems to handle it fine for controllers, though.
>
>I tried creating a class SomeModule::SomeClass. I have a file named
>''some_class.rb'' in app/models/some_module. I keep getting
this:
>
>/usr/lib/ruby/gems/1.8/gems/activesupport-1.1.1/lib/active_support/dependencies.rb:186:in
>`const_missing'': uninitialized constant SomeClass (NameError)
>
>So, I tried creating a file called ''some_module.rb'' in
app/models that had this:
>
>require_dependency ''some_module/some_class''
>
>
require_dependency, like require requires the name of the file, not a
class in the file
so, in the controller add
require_dependency ''some_module''
class BogusController < ApplicationController
def index
test = SomeModule::SomeClass.new
render(:text => test.hello)
end
end
in file: lib/some_module.rb
module SomeModule
class SomeClass
def hello
"hello"
end
end
end
>that seemed to work unless I have a class named SomeClass without a
>module name, which kind of defeats the purpose of modules.
>
>So, is there any way I can get this to work, or should I put all this
>code in lib instead?
>
>Kurtis Seebaldt
>_______________________________________________
>Rails mailing list
>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
>http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>