Binding text_field et al to object.attribute.name

Hi all,

Suppose I have a PurchaseItem model which refers to Product model…

class Product < ActiveRecord::Base
has_many :purchase_items
end

class PurchaseItem < ActiveRecord::Base
belongs_to :product
end

To keep things simple, one of the attribute of the Product model is
title.

On the interface, I have a textfield that I need to bind with
@purchase_item.product.title.

text_field ‘purchase_item’, ‘product.title’ doesn’t work for me.

How to achieve this using Rails 1.1.4? Does this feature exist by
default in Edge?

Oh and one more thing, will it matter if the attribute is an
ActiveRecord object or a value object like Money?

Thank you very much.

Regards,
John.

John I. wrote:

To keep things simple, one of the attribute of the Product model is title.

On the interface, I have a textfield that I need to bind with
@purchase_item.product.title.

text_field ‘purchase_item’, ‘product.title’ doesn’t work for me.

How to achieve this using Rails 1.1.4? Does this feature exist by
default in Edge?

Add to the PurchaseItem model methods:

def product_title
product.title
end

def product_title= (t)
product.title = t
end

Then you can use

text_field ‘purchase_item’, ‘product_title’


We develop, watch us RoR, in numbers too big to ignore.

On Jul 17, 2006, at 12:09 PM, Mark Reginald J. wrote:

Then you can use

text_field ‘purchase_item’, ‘product_title’

Of course I can do that. I was doing exactly that way before I made
my post.
However, I feel that it’s kind of a messy hack.
Are you sure there is no ‘better’ solution?

Thanks anyway

Best regards,
John

John I. wrote:

Are you sure there is no ‘better’ solution?

Another option is http://dev.rubyonrails.com/ticket/2053


We develop, watch us RoR, in numbers too big to ignore.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs