rails-settings
rails-settings copied to clipboard
Global Settings
Hi,
Is there anyway you could show usage for global settings?
I don't want settings stored on the instance level but on some something like:
FooSettings.time_stamp = DateTime.now
I only ever want a single FooSettings instance.
Thanks!
+1
+1 this would be an excellent addition
+1, that's what the original "rails-settings" was all about.
+1
FWIW: We ended up just doing a GlobalSettings
model:
CREATE TABLE global_settings (
id integer NOT NULL,
var character varying(255) NOT NULL,
value text,
thing_id integer,
thing_type character varying(30),
created_at timestamp without time zone,
updated_at timestamp without time zone
);
class GlobalSetting < ActiveRecord::Base
attr_accessible :var,
:value,
:thing_id,
:thing_type,
:created_at,
:updated_at
serialize :value
end
class GlobalSettings
def self.get(name)
setting = GlobalSetting.find_by(var: name)
setting && setting.value
end
end
#
class V1::SettingsController < ActionController::Base
# ...
def defaults
render :text => GlobalSettings.get(:ios_settings)
end
end
This is awesome, thanks for coming through on this!
A fork of this repo: https://github.com/huacnlee/rails-settings-cached implements it. See: https://github.com/huacnlee/rails-settings-cached#usage
I use it in my project without a problems. Although its latest release seems in 2011 in github, it is active and somehow bundler will install latest release (not the one from 2011) correctly.
Maybe somebody could dig through at create a PR on this one.
+1
+1
+1
I know I'm late to the party, but if anyone is looking to restore that global Settings
class, here's a very basic model that could serve as a starting point. For us, since we didn't use many of the features that 1.x offered on the Settings
class, and we didn't use instance level settings at all, we were able to replace this gem with this model entirely. It uses the same schema that the gem does (you can drop the target_id/target_type columns if all of your settings are global). With some modification, this could also work side-by-side with this gem to restore the global Settings
while also using instance level settings.
https://gist.github.com/jimryan/1ff3d6a19f9ec1abd6612864a05e3185
+1