user117399
user117399

Reputation:

How to support user-generated Model attributes (Rails 3.1)

My app has a User model, and a Game model. I want each user to be able to add their own personal set of Game attributes (that are only available/visible to them) aside from the ones I already have predefined.

What's the most 'Rails' way of going about this?

Upvotes: 1

Views: 110

Answers (2)

smathy
smathy

Reputation: 27961

You'll store per-user settings in the join table between User and Game and then your association between those two models will be a has_many :through - meaning that you'll have a join model giving you access to the attributes.

Upvotes: 1

apneadiving
apneadiving

Reputation: 115531

I'd advise you to use serialization:

Advantages:

  • it's much flexible and built in

  • you can store data the way you want (even your custom class)

Drawback:

  • it would be hard to get your data back from database if you finally change your web framework.

More doc see here.

Upvotes: 1

Related Questions