Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Model namespace trouble

#2548

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 ?

Reported by BotWebApps · April 23rd, 2009 @ 11:20 AM

State: invalid
Milestone: 3.x
Assigned to: nobody
Importance: none

Activity

  1. Andriy Tyurnikov
    Andriy Tyurnikov

    script/generate model Bar::Foo namespacing via subdirectories in models should help you to avoid such problems.

    April 26th, 2009 @ 09:26 AM

  2. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  3. Mike Riley
    Mike Riley
    • 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

    July 29th, 2010 @ 05:08 PM