Nested preference settings with activerecord store
As per this Episode 191 is there any way I can add nested settings? for example:
{
"wants_reminders": true,
"wants_deals_offers": true,
"subscribed_to_newsletter": true,
"something_here": {
"option1": "data",
"option2": "data"
}
There's nothing builtin to Rails to read or write option1
or option2
directly.
You can assign a hash to something_here
and it will work just fine though so you can write your own helper method to read from that, just have to assign the hash though when you want to change it.
Thanks for the reply mate, so basically i want to store
{
"energy_provider": {
"name": "data",
"renewal": "data"
},
"insurance_provider": {
"name": "data",
"renewal": "data"
}
}
Do you think it would be best to have JSONB fields in the table to store these then? Or do you know of a more efficient way you could suggest please?
I found this article, which seems to be interesting. And maybe worth a look at.