I am dealing with a large project. I use a lot of STI and therfore have
a lot of models. I''d like to use namespaces to help organize my models
but am having trouble getting started.
I have a base model Term::Base located in /app/models/term/base.rb:
class Term::Base < ActiveRecord::Base
set_table_name "terms"
end
I have a non-namespaced client model:
class Client < ActiveRecord::Base
has_many :terms, :class_name => "Term::Base"
end
When I try to access a client''s terms, i get:
>> Client.find(1).terms
ArgumentError:
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.1.5618/lib/active_support/dependencies.rb:399:in
`to_constant_name'': Anonymous modules have no name to be referenced by
from
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5618/lib/active_record/base.rb:1363:in
`compute_type''
from
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.1.5618/lib/active_support/dependencies.rb:211:in
`qualified_name_for''
from
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.1.5618/lib/active_support/dependencies.rb:470:in
`const_missing''
from (eval):1:in `compute_type''
from
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5618/lib/active_record/base.rb:1066:in
`instantiate_without_callbacks''
from
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5618/lib/active_record/callbacks.rb:204:in
`instantiate''
from
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5618/lib/active_record/base.rb:424:in
`find_by_sql''
from
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5618/lib/active_record/base.rb:424:in
`collect!''
from
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5618/lib/active_record/base.rb:424:in
`find_by_sql''
from
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5618/lib/active_record/base.rb:994:in
`find_every''
from
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5618/lib/active_record/base.rb:415:in
`find''
from
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5618/lib/active_record/associations/has_many_association.rb:91:in
`find''
from
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5618/lib/active_record/associations/association_collection.rb:159:in
`find_target''
from
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5618/lib/active_record/associations/has_many_association.rb:123:in
`load_target''
from
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5618/lib/active_record/associations/association_proxy.rb:122:in
`method_missing''
from
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4.5618/lib/active_record/associations/has_many_association.rb:98:in
`method_missing''
from /usr/local/lib/ruby/1.8/irb.rb:298:in `output_value''
from /usr/local/lib/ruby/1.8/irb.rb:151:in `eval_input''
from /usr/local/lib/ruby/1.8/irb.rb:259:in `signal_status''
from /usr/local/lib/ruby/1.8/irb.rb:147:in `eval_input''
from /usr/local/lib/ruby/1.8/irb.rb:146:in `eval_input''
from /usr/local/lib/ruby/1.8/irb.rb:70:in `start''
from /usr/local/lib/ruby/1.8/irb.rb:69:in `catch''
from /usr/local/lib/ruby/1.8/irb.rb:69:in `start''
from /usr/local/bin/irb:13>>
It works if I "unnamespace" my Term::* models by putting them in
/app/models/ and removing the Term:: prefixes and of course removing
the :class_name => "Term::Base" from the association.
Any ideas fellas?
Todd Boland
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---