huacnlee / rails-settings-cached

Global settings for your Rails application.
Other
1.06k stars 202 forks source link

Model settings in 2.x #160

Closed mbajur closed 5 years ago

mbajur commented 5 years ago

Hey!

I recently updated from 0.x to 2.x and noticed there is no way to have a settings per model (eg. i had a User model with include RailsSettings::Extend so i could use User.last.settings.foo = :bar.

Is that feature deprecated in 2.x ? Are you planning to support that scenario?

huacnlee commented 5 years ago

No more that supports in 2.x.

If your project has used RailsSettings::Extend, you can continue use rails-setting-cached 0.x.

When you have a new project, you can try 2.x, and use ActiveRecord serialize instead of the RailsSettings::Extend feature.

nicbet commented 5 years ago

@huacnlee Is there an example of how one would replace with RailsSettings::Extend with ActiveRecord serialize? I'd love to use version 2.x but it's unclear how to use this gem in the context of model specific settings. I'd argue that most applications have the requirements for both, global settings and model specific settings. Any help / documentation much appreciated.

huacnlee commented 5 years ago

There will be no longer have that feature in 2.x.

If you wants upgrade to 2.x, I recommend you to write a migrations to transfer the old model special setting values into Rails serialize field.

To do this it’s not complex, if your application not have too much records. So, you can easy to do that.

huacnlee commented 5 years ago

https://github.com/huacnlee/rails-settings-cached/tree/master#backward-compatible-to-support-0x-scoped-settings

@nicbet @mbajur

Here is an example for backward-compatible scoped setting in 2.x

nicbet commented 5 years ago

Excellent, thanks for the guidance @huacnlee!

huacnlee commented 5 years ago

https://github.com/ruby-china/homeland/pull/1113/commits/6dd4dc293cfb7818631e36d9ad41bf83bc4ea4dc

Here is an example for upgrade from 0.x to 2.x

https://github.com/ruby-china/homeland/pull/1113