The delegate method allows you to add contained objects methods to your current objects methods. For example suppose you have two models User and Organization….
class User < ActiveRecord::Base belongs_to :organization
class Organization < ActiveRecord::Base
has_many :users
Ok now lets say that you want to access the taxid for the employee but the taxid is in the organizations table, you would normally have to access it like this….
@a_user.organization.taxid
but with the delegate method you can insert
class User < ActiveRecord::Base belongs_to :organization
delegate :taxid, :to => :organization
and now to can skip the middle man and do…
@a_user.taxid
which returns the same result
Other Posts That Might Interest You

