Rails 3 Application/User Settings best practice?

后端 未结 4 1556
慢半拍i
慢半拍i 2020-12-28 16:32

I have a current need for allowing both admin configurable global settings as well as per-user configurable settings within a Rails 3 app.

Are there any gems or best

相关标签:
4条回答
  • 2020-12-28 17:09

    As always right after asking for help my search bears fruit. Found Georg Ledermann's fork of rails-settings that looks like it will do just what I need.

    0 讨论(0)
  • 2020-12-28 17:11

    For rails 4, if you are using postgresql, you can use HStore, which is just like a serializable attribute, but you do SQL queries with it.

    For rails 3, you can use activerecord-postgres-hstore gem.

    0 讨论(0)
  • 2020-12-28 17:14

    May also want to look at https://github.com/railsjedi/rails_config. Amongst it's many features:

    • Global settings.yml
    • Per-environment settings files (settings/development.yml, settings/production.yml etc.)
    • Local settings files (settings.local.yml, settings/development.local.yml, etc. )
    • Embedded ERB support
    • Rails 3 / Padrino / Sinatra support
    0 讨论(0)
  • Not sure I would look for a library for this function.

    For global settings, I would create a config/application.yml file and read it in environment.rb and set it to an APP_CONFIG global. Then, I would override those settings on a per-user basis by adding a text column to the user table with json-encoded settings hash. Add a method to the user model that grabs APP_CONFIG and does a deep merge on the decoded user settings.

    Another option would be to create a settings table, with a user_id column, and columns for each setting. One row with a null user_id would represent global settings. If a row exists for the current user, any non-nil values would override the global settings row.

    0 讨论(0)
提交回复
热议问题