cleaner way to write this...

Don't put view code (HTML) in your models!

Better to put that in a helper.

Tom Mornini wrote:

> Within the last few days I saw an excellent example of this but can't > find the link. So... I thought I'd ask the experts. > > In my addressbook model, I wanted to be able to just say > thing.full_address to return a preformatted version of the customers > entire address. Something like this: > > # from addressbook model > def full_address > full = first_name + ' ' + last_name + '<br>' + address1 + '<br>' > unless address2.blank?; full += address2 + "<br>"; end > full += city + ' ' + state + ',' + zip > full > end > > I'm sure there's a cleaner more compact way to do this, but this is > the > extent of my ruby knowledge at this point. > > > Any help cleaning / compacting this would be greatly appriciated.

Don't put view code (HTML) in your models!

Better to put that in a helper.

-- -- Tom Mornini

I'm with Tom on this one. Make a partial that properly formats the address when passed the object.

FWIW, the format I think you were looking for is like this...

def print_stuff "#{variable1}-#{variable2}" end

_Kevin www.sciwerks.com