Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 Application/User Settings best practice?

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 practices that work well for this situation?

I've found a couple of gems and blog posts but they all date back to 2006-08 and are no longer maintained. Any pointers would be appreciated, thanks.

Note: I have seen this question with the serialised hash response but in my particular case the ability to query the database for users based on their settings is required - I don't think a serialized hash would work well in that situation.

like image 645
Kevin Ansfield Avatar asked Nov 29 '10 17:11

Kevin Ansfield


2 Answers

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.

like image 67
Kevin Ansfield Avatar answered Sep 20 '22 16:09

Kevin Ansfield


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.

like image 28
aceofspades Avatar answered Sep 18 '22 16:09

aceofspades