delegate_belongs_toseems to be replaced by pahanix delegates_attributes_to , but the main idea is this.
Say you have a model Officein your Rails application that has a field address, and you also have a model Employeethat relates to the office:
class Office < AcitveRecord::Base
end
class Employee < ActiveRecord::Base
belongs_to :office
end
If you want to know the address of an employee, you will need to do the following:
>> emp.office.address
=> "Edinburgh"
However, if you used delegate_belongs_toas follows:
class Employee < ActiveRecord::Base
belongs_to :office
delegate_belongs_to :office
end
You will get direct access to the model attributes Office:
>> emp.address
=> "Edinburgh"
github . , faber github.