views:

35

answers:

1

Is this any possible?

I'd like to have something like

User.avatar.to_url

which would then print the full URL address for the user's avatar image.

=> "http://url.com/images/avatars/1262694724.jpeg"

Of course, the avatar attribute would be an existing column on the users table which contains a long integer.

The to_url method im thinking on would be defined as:

def to_url
    "http://url.com/images/avatars/#{self}.jpeg"
end
+4  A: 

If avatar is an attribute (as opposed to another model/association) then you're going to save yourself a world of trouble by just doing:

def avatar_url
  "http://url.com/images/avatars/#{avatar}.jpeg"
end
thenduks
Agree, there's no good reason to be adding a to_url to your attribute. IMO, that kind of meta-programming should be reserved for situations which have a really good justification.
fd