Closed Svashta closed 8 years ago
Ok, so i've tested a bit more and i am getting a little bit confused. As i said earlier, before the update i had a default_settings initializer, where values were defined like this:
Setting.defaults['some.nested.key'] = "value"
I had to change this to use app.yml, where i have defined it like so:
some:
nested:
key: value
I didn't change my settings controller logic (updating values), and in the views for example i am accesing this value like before the update: user.settings["some.nested.key"]
. Updating this value is done the same way user.settings["some.nested.key"] = "updated value"
.
Now, when i go to console i have two different values:
Setting["some.nested.key"] = "value"
user.setting["some.nested.key"] = "updated value"
Quite logical i would say. But what i don't understand is the get_all behaviour which returns both keys! user.settings.get_all:
{ "some.nested.key" => "updated value",
some => { nested => { key: "value" } }
}
I think the problem is in how key/value should be saved in the database. Please, can someone help me understand, how key should be saved in the database, so that it is then read by the get_all as yaml?
For example, if i update simple first level key of "something", it will then be read from DB and shown inside get_all hash (taking precedence to yaml config value).
But as soon as I have multilevel values, they are saved in the DB in a wrong format (i think) and hash than returns both values (DB and YAML). DB value is flat "nested.key" and config value is in a hash format.
How do i save multilevel settings in the database so that get_all will return only DB value if exists, and if not a config value?
Thx
OK, I see now that settings can't be actually saved in nested way, so it should just be flat definitions
@Svashta Yes, in currently rails-settings-cached has not supported with nested key:
https://github.com/huacnlee/rails-settings-cached/issues/99#issuecomment-217451178
Hi,
I am not sure if I am doing something wrong, but today, after i have updated a gem to the latest version, i am getting bunch of weird behavior.
First i had problems with the initializer, which seems to be replaced with YML file. I've migrated all the settings done in initilizer to te settings yaml, with a normal yml structure (before it was just flat...).
Now some settings work, but some have weird behaviour, like the value is not read properly. For example, when i change something in the GUI, it should be persisted in the DB. And in the GUI i can see a proper value. In console however (and controller where i actually do this) current_user.setting.get_all seems to be fetching YML values - which is a bummer - I know this was pretty much working before the update.
Also, I am noticing, that values sometimes update, but sometimes just don't. Very weird.
Is there some kind of migration doc that i am not aware of? Should i do something else that i have missed somewhere?
I am using Rails 4.2.5 with redis cache store.