This project is archived and is in readonly mode.
Model namespace trouble
Reported by BotWebApps | April 23rd, 2009 @ 11:20 AM | in 3.x
Hi,
I have trouble trying to put a model in a namespace...
For example, I have a "normal" model (outside of my namespace) named "Foo" and a namespace named "Bar", which have only one model named "Baz".
app/models/foo.rb
class Foo < ActiveRecord::Base
end
app/models/bar/baz.rb
module Bar
class Baz < ActiveRecord::Base
end
end
>> Bar::Baz
=> Bar::Baz # return the right model
>> Bar::Quux
=> NameError: uninitialized constant Bar::Quux # raise an error as expected
Everything is normal until here... but when I try to call an model which don't exist into my namespace, but exists outside of the namespace, it returns a model the first time, and an error the following times...
>> Bar::Foo
=> Foo # return a model instead of raise an error
>> Bar::Foo # call again
=> NameError: uninitialized constant Bar::Foo # return an error, which normaly have to be raised the first time...
Is there anybody who can help me please ?
Comments and changes to this ticket
-
Andriy Tyurnikov April 26th, 2009 @ 09:26 AM
script/generate model Bar::Foo namespacing via subdirectories in models should help you to avoid such problems.
-
Mike Riley July 29th, 2010 @ 05:08 PM
- State changed from new to invalid
- Importance changed from to
Hello,
Just checking in to see if Andriy's reply helped you past this. I am going to mark this as invalid as this is not a bug with Rails itself. If you do find that there is a bug related to this can you provide a patch and a failing test?
Mike Riley
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Referenced by
- 5735 Weird classes namespace whith cache_classes = false https://rails.lighthouseapp.com/projects/8994/tickets/25...