0

Here's my challenge. I have a key/value set that I want to tie to a model. These are my specific requirements:

  • I want the hash to be stored as a serialized JSON object in the model's table instead of in a separate table
  • I want to be able to pre-define the valid keys within the model itself
  • I want to be able to set a strong type for each key and automatically perform validations. I don't want to have to write validation functions for each individual attribute unless it needs a validation out of the basic data type scope.
  • I would LOVE to be able to magically access the attributes inside a form generator (f.input :my_key) and have the form generator recognize that :my_key is of type :boolean and create a checkbox instead of a generic text input. The same for other data types.

There are a few different ways to solve this problem, and lots of opinions for both. I read over this answer from 5 years ago:

Best approach to save user preferences?

It seems that many/most of those plugins have been abandoned. Anything else come out in the last 5 years that matches my criteria?

Community
  • 1
  • 1
kid_drew
  • 3,857
  • 6
  • 28
  • 38

1 Answers1

1

Your question is a bit open-ended, but as far as I can see your needs, they should be met with using Hashie gem.

Arkhitech
  • 475
  • 3
  • 11