On May 3, 8:18 pm, Bloudermilk <bren...@apwit.com> wrote:
> 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.

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 Jones

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to