Settings and options - MikeBlyth/mission_database GitHub Wiki
Information for Developers
This is rather confusing right now but might get cleaned up. Meanwhile what we have is two completely different systems for handling configuration settings.
-
SiteSetting is a normal ActiveRecord model. See https://github.com/paulca/configurable_engine. Since this is an ActiveRecord, we have a controller site_settings_controller.rb, views, etc. and it’s defined in schema.rb. Administrators can change these settings at run time using the /admin/site_settings path.
“Configurable lets you define app-wide configuration variables and values in config/configurable.yml. These can then be accessed throughout your app. If you or your app users need to change these variables, Configurable stores new values in the database.”
(This configuration or settings manager works, but I have lost track of how and why :-(. Naturally, it would be a good idea to go back and take a look at the whole business of settings.)
a. I don’t know when the defaults are put into the database. If you clear the database with cleaner, then restart Rails, you don’t get the defaults back. Defaults are not restored on each run; the database holds the permanent values.
b. Configuration: set in config/site_settings.yml. This is essentially a table-definition file. Default values are stored in this file also. Example:
twilio_api_version:
name: Twilio API Version
type: string
default: '2010-04-01'
c. Accessing a setting from within program: `SiteSetting.page_size` or `SiteSetting[:page_size]`
d. Changing a setting from within program:
`SiteSetting.find_by_name('sms_gateway').update_attribute(:value, 'vgate')`
The documents say you can just use create, as below, but that leaves you with two records in the table with the same key and different values.
`SiteSetting.create!(:name => 'sms_gateway ', :value => 'vgate') # !doesn’t work!`
e. In testing: the easiest way to change a value temporarily would be to stub the method, e.g.
`SiteSetting.stub(:sms_gateway).and_return('testing_gateway')`
f. `spec/support/secret_credentials.rb` will set up values for testing. Again, after it is run, values will persist in the database.
-
The other config system uses Binary Systems’ Settings Logic (https://github.com/binarylogic/settingslogic). Settings are stored in config/applications_settings.yml and are reloaded with every restart. The idea is that these settings will be configured by the site administrator and not changed (often). Still, some of the settings currently in this file may be better moved to the SiteSettings where they can be changed easily without having to then push the new setup to the server.
a. Accessing a setting from within program:
Setting.page_sizeorSetting[:page_size]b. Changing a setting from within program:
Setting.site[:org] = 'SIM Nigeria'. Note that the last level of nesting (:org in this example) must be in brackets, but the higher levels must not be!