Easy way to add properties to a model?


I have a model (let’s say User) and I would like to add any number of
user-defined-settings to this Model. I created a UserSetting Model
with user_id, key and value. I connected them with has_many. I know
how to access these properties from a user but I would like some
methods like user.hasProperty? / user.getProperty …

I think I know how to write these methods/finders myself but it seems
like a pretty common problem to me, which means there could be an
easier way of doing the same. Is there?


On Jan 26, 2006, at 5:44 AM, Frank S. wrote:

easier way of doing the same. Is there?

Nothing automatic, but the code seems trivial anyway:

def get_property(property)
alias has_property? get_property

Duane J.

On 1/26/06, Duane J. [email protected] wrote:

alias has_property? get_property
I think you misunderstood me. If I’m not mistaken, you code would
return the same property for every user… But these property will be
different for every user.



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