# Model Namespace?

**URL:** <https://www.ruby-forum.com/t/model-namespace/190546>\
**Category:** Rails\
**Created:** [June 22, 2010, 4:12pm UTC](https://www.ruby-forum.com/t/model-namespace/190546 "2010-06-22T16:12:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ferblape](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/73ab20/32.png) [@ferblape](https://www.ruby-forum.com/u/ferblape)\
**Post date:** [June 22, 2010, 4:12pm UTC](https://www.ruby-forum.com/t/model-namespace/190546/1 "2010-06-22T16:12:32Z")

</div>

Hello,

Sorry if this looks silly, but I trying to learn Ruby on Rails best  
practices.

I have a model called “Users” and a model called “Projects”. Now I need  
to  
implement a “status” field to each one of them. Each User/Project  
belongs\_to a status.  
But because they have different kind of status possibilities, I will  
need 2  
new models: UserStatus and ProjectStatus.

Something like:

_- User_  
– “name”  
– “gender”, …  
– “status\_id” (this must refers to UserStatus)

_- UserStatus_  
– “name” (like active, fired, etc)

_- Project_  
– “name”, …  
– “status\_id” (this must refers to ProjectStatus)

_- ProjectStatus_  
– “name” (opened, completed, pending, etc)

Also, to keep my application cleaner, I would like to have the  
ProjectStatus  
viewers inside my Project viewer folder.  
Something like:  
/app/views/projects/new.html.erb  
/app/views/projects/status/new.html.erb

Is there any convention of doing this? Is that the correct way of doing  
what  
I want? What should I search for? Can “namespaces” help me? Am I picking  
good model names?

## Thanks,

Fernando B.

---

<div class="post-metadata">

**Author:** ![ferblape](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/73ab20/32.png) [@ferblape](https://www.ruby-forum.com/u/ferblape)\
**Post date:** [June 22, 2010, 4:19pm UTC](https://www.ruby-forum.com/t/model-namespace/190546/2 "2010-06-22T16:19:34Z")

</div>

On 22 June 2010 15:11, Fernando B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have a model called “Users” and a model called “Projects”. Now I need to  
> implement a “status” field to each one of them. Each User/Project  
> belongs\_to a status.

If you’re implementing states, use a state machine.

I use AASM at a preference, but there are lots of alternatives.

> **[GitHub - rubyist/aasm: AASM - State machines for Ruby classes](https://github.com/rubyist/aasm)**
>
> AASM - State machines for Ruby classes. Contribute to rubyist/aasm development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![ferblape](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/73ab20/32.png) [@ferblape](https://www.ruby-forum.com/u/ferblape)\
**Post date:** [June 23, 2010, 12:23am UTC](https://www.ruby-forum.com/t/model-namespace/190546/3 "2010-06-23T00:23:12Z")

</div>

You could add a status field to your higher level models - for  
example, add ‘status’ to User as an integer and then store your  
status:descriptions in a common status table. So you store an integer  
referring to the status in your User model and if you need to display  
the description, query the status table with the id.

Or you could create the status tables and setup the relation between  
them - both sides - the User would have\_one =\> :user\_status and the  
belongs\_to in the user\_status model file.

I don’t know if I would put the status views below Users or Projects  
though. Depending on how many controllers you have - if it’s a lot  
then try to put the status under the User or Project views. It’s more  
than likely they should be beside the other controllers as you will  
probably be adding some functionality to the status controllers such  
as notifying someone if a project is in X status for some amount of  
time. Also I would think the status controllers would be easier to  
reuse if kept higher in the hierarchy.

In any case, you can put links to change the status anywhere you like.  
Simply Rails 2 contains some very good examples of this using  
javascript. You might want to check it out.
