Working with namepaced model09 Oct 2009
Sometime we have to work with namespaced model in Ruby on Rails to keep our code clean.
For example: I have model named as
Attandance.rb, Sometime to keep our code clean we have to put them in custom dir. This scenario is normal while working with two or three modules. for ex. I have three module in a project for school.
Admin module, Teachers module and a Student module. So it is better to put all stuff that belongs to teacher in a custom dir named
Be sure that folder name does not match any model that have been put under this folder. I prefer to use plural names for these directories. But now begins the real headache; to access model under the
Teachers directory I have to write this
Teachers::Attendance.find and all that. And for sure it will be a headache while translating with I18n.
But this violates Ruby’s very own DRY approach. So to keep being DRY do the below written things.
And you are done.
now you can have access to these model like others
Attendance.find() and while translating you can write normally as you do whith other models.
Don’t go on Unicode they are not real. This is a little thing but it solves many problem that can come in your way.