I have a site in rails and want to have site-wide settings. One part of my app can notify the admin by SMS if a specific event happens. This is an example of a feature that
I will put a few remarks to the previous answers:
id field. Since we should have id field in a Rails app anyway, it's a good tradeoffIf we apply these modifications, the solution becomes very easy:
# migration
create_table :settings, id: false do |t|
t.integer :id, null: false, primary_key: true, default: 1, index: {unique: true}
t.integer :setting1
t.integer :setting2
...
end
# model
class Settings < ApplicationRecord
def self.instance
first_or_create!(...)
end
end