views:

35

answers:

1

The gem can help like this :

class Book
  belongs_to :author
end

book = Book.first
book.author_name  #=> same as book.author.name
book.provide( :author_name, :title ) #=> will automatically map like this: { :title => book.title, :author_name => book.author.name }

Is there any gem help ?? Thanks!

+1  A: 

Take a look at the rails Delegate module:

class Invoice < Struct.new(:client)
  delegate :name, :address, :to => :client, :prefix => :customer
end

invoice = Invoice.new(john_doe)
invoice.customer_name    # => "John Doe"
invoice.customer_address # => "Vimmersvej 13"
fractious