# Namespace Issues

**URL:** <https://www.ruby-forum.com/t/namespace-issues/95153>\
**Category:** Engines Development\
**Created:** [January 13, 2006, 6:14pm UTC](https://www.ruby-forum.com/t/namespace-issues/95153 "2006-01-13T18:14:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![maurocicio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@maurocicio](https://www.ruby-forum.com/u/maurocicio)\
**Post date:** [January 13, 2006, 6:14pm UTC](https://www.ruby-forum.com/t/namespace-issues/95153/1 "2006-01-13T18:14:18Z")

</div>

## Abstract: It seems that the AnyModule::AnyModel shadows AnyModel.

If you are in a hurry, please skip to “The Problem”.

## The idea

One important topic in architecting engines is to make them as isolated  
as possible in terms of namespace and database schema (if supported).

In this way we can be confident that our engine can be used by other  
applications without risk of name clashes.

## Example

As an example, let’s assume that we want to create a ‘task\_list\_engine’.  
Ideally we would like to have a TaskList namespace and, for the  
databases that support it, a separate task\_list schema.  
Given that we want to represent the concept of Category in our task  
list, we will have a TaskList::Category model, a  
askList::CategoryController and a task\_list.categories table in our  
database (task\_list = schema name, categories = table name).

## The Problem

Easy to check:  
1 - create a test rails application (e.g. tasklist)  
2 - setup a db (e.g. tasklist\_dev) with a table (e.g. categories)  
3 - from RAILS\_ROOT  
$ ./script generate scaffold category  
4 - run the application and  
point to [http://localhost:3000/categories](http://localhost:3000/categories)  
you should see the usual good stuff.  
5 - $ ./script generate model task\_list/category

Now tha application is broken and you get:  
“uninitialized constant Category” error.

It seems that the Task\_List::Category shadows Category.  
Can anybody explain why? Is it a Rails flaw?

Mauro

---

<div class="post-metadata">

**Author:** ![maurocicio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@maurocicio](https://www.ruby-forum.com/u/maurocicio)\
**Post date:** [January 14, 2006, 12:25am UTC](https://www.ruby-forum.com/t/namespace-issues/95153/2 "2006-01-14T00:25:42Z")

</div>

I can’t explain why, but I can confirm that rails, models, and modules  
dont  
seem to get along. I tried orginzing a project of mine like that and got  
very weird problems popping up, that you’ve probably seen as well. I  
think  
this would be a good thing to pester the rails core team about. I can’t  
imagine they would say seperating out your models into seperate modules  
would be a bad idea.

-Nick

p.s. Using controllers in different modules hasn’t been problem. Have  
done  
that quite a bit with no surprising results.

---

<div class="post-metadata">

**Author:** ![maurocicio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@maurocicio](https://www.ruby-forum.com/u/maurocicio)\
**Post date:** [January 14, 2006, 2:58am UTC](https://www.ruby-forum.com/t/namespace-issues/95153/3 "2006-01-14T02:58:30Z")

</div>

Nick S. wrote:

> I can’t explain why, but I can confirm that rails, models, and modules  
> dont  
> seem to get along. I tried orginzing a project of mine like that and got  
> very weird problems popping up, that you’ve probably seen as well. I  
> think  
> this would be a good thing to pester the rails core team about.

Definetely. There were a few mails on this topic on the rails-core  
mailing list, but unfortunately no response from the core team.

---

<div class="post-metadata">

**Author:** ![maurocicio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@maurocicio](https://www.ruby-forum.com/u/maurocicio)\
**Post date:** [January 14, 2006, 10:19am UTC](https://www.ruby-forum.com/t/namespace-issues/95153/4 "2006-01-14T10:19:34Z")

</div>

Hi James,

I guess that what you suggest is the most sensible way to go about it.

My original intention (The Idea 😉 ) was to improve the engines plugin  
so that it could handle the modularization. What I mean: given the  
ENGINE\_NAME the engine generator creates all the models, controllers and  
views with their own ENGINE\_NAME subdirectories - mapped to the  
ENGINE\_NAME:: namespace.

For databases like postgres you could go even further: the model  
ENGINE\_NAME::MODEL\_NAME \< ActiveRecord::Base gets mapped to the table  
ENGINE\_NAME.MODEL\_NAMEs

I agree to all the following (1a is my add on):  
1 - Each part gets loaded into its own namespace.  
1a- Clever Database mapping  
2 - Demonstrate to community.  
3 - Pray for adoption.  
4 - Well, I don’t drink… Virtual beer for me!

I’ll have a look to the bug over the weekend.

Mauro

---

<div class="post-metadata">

**Author:** ![maurocicio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@maurocicio](https://www.ruby-forum.com/u/maurocicio)\
**Post date:** [January 14, 2006, 3:11am UTC](https://www.ruby-forum.com/t/namespace-issues/95153/5 "2006-01-14T03:11:43Z")

</div>

Super-secret idea: rewrite the Rails plugin system (and any other  
parts of Rails dependency-mechanisms required) so that it handles  
namespaces in a consistent, predicable, controllable and safe way.  
Incorporate some form of ‘engine-style’ features into that system.  
Make /app an implicit ‘engine’ at the top of the pile for elegance of  
implementation. Each part gets loaded into its own namespace.  
Demonstrate to community. Pray for adoption. Have a beer.

I have some ideas how to do this, but nothing is clear yet. First  
though, if you guys could help me track down this bug…  
[https://opensvn.csie.org/traccgi/rails\_engines/trac.cgi/ticket/53](https://opensvn.csie.org/traccgi/rails_engines/trac.cgi/ticket/53)

- james
