# STI helper/model mapper

**URL:** <https://www.ruby-forum.com/t/sti-helper-model-mapper/188018>\
**Category:** Rails\
**Created:** [May 4, 2010, 10:30am UTC](https://www.ruby-forum.com/t/sti-helper-model-mapper/188018 "2010-05-04T10:30:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 4, 2010, 10:30am UTC](https://www.ruby-forum.com/t/sti-helper-model-mapper/188018/1 "2010-05-04T10:30:47Z")

</div>

I am currently using STI to manage three different types of Users on a  
site. I find this to be a great solution when it comes to DRYing  
authentication and basic fields for each type of user. My only caveat  
with this method is adding type specific fields to the three classes  
of users. Currently each type has it’s own \_\_\_\_Profile model  
(AdminProfile, CatProfile, DogProfile, etc.). To avoid always having  
to do things like cat.cat\_profile.fur\_color, I’ve been manually  
mapping attributes of the \_\_\_\_Profile classes to their respective user  
class so I can just do cat.fur\_color. This makes my code a lot cleaner  
on the controller and view side, but is huge mess on the model side. I  
am wondering if there is a plugin/gem to do these kinds of mappings  
automatically.

Thanks for your help,  
Brendan

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 6, 2010, 4:19am UTC](https://www.ruby-forum.com/t/sti-helper-model-mapper/188018/2 "2010-05-06T04:19:07Z")

</div>

On May 3, 8:18 pm, Bloudermilk [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> am wondering if there is a plugin/gem to do these kinds of mappings  
> automatically.

You’re probably looking for the ‘delegate’ method that ActiveSupport  
defines. Here’s an example:

class Foo \< ActiveRecord::Base  
belongs\_to :bar  
end

class Bar \< ActiveRecord::Base  
has\_one :foo

delegate :method\_one, :method\_two, :method\_three, :to =\> :foo  
end

If maintaining that list becomes burdensome, you could probably  
metaprogram something by grabbing Foo.attributes or the like.

–Matt J.
