rails-settings icon indicating copy to clipboard operation
rails-settings copied to clipboard

Global Settings

Open brancusi opened this issue 10 years ago • 12 comments

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!

brancusi avatar Jul 12 '14 00:07 brancusi

+1

christianrojas avatar Jul 22 '14 10:07 christianrojas

+1 this would be an excellent addition

theoretick avatar Sep 03 '14 18:09 theoretick

+1, that's what the original "rails-settings" was all about.

jchilton avatar Sep 08 '14 07:09 jchilton

+1

dirtyhenry avatar Oct 07 '14 10:10 dirtyhenry

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

theoretick avatar Oct 07 '14 16:10 theoretick

This is awesome, thanks for coming through on this!

jchilton avatar Oct 12 '14 19:10 jchilton

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.

mtozlu avatar Sep 04 '15 20:09 mtozlu

+1

botularius avatar Dec 21 '15 17:12 botularius

+1

fabn avatar Feb 17 '16 00:02 fabn

+1

neohunter avatar Jun 09 '16 14:06 neohunter

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

jimryan avatar Mar 24 '17 01:03 jimryan

+1

bastengao avatar Aug 08 '18 08:08 bastengao