Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global Settings #60

Open
brancusi opened this issue Jul 12, 2014 · 12 comments
Open

Global Settings #60

brancusi opened this issue Jul 12, 2014 · 12 comments

Comments

@brancusi
Copy link

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!

@christianrojas
Copy link

+1

@theoretick
Copy link

+1 this would be an excellent addition

@jchilton
Copy link

jchilton commented Sep 8, 2014

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

@dirtyhenry
Copy link

+1

@theoretick
Copy link

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

@jchilton
Copy link

This is awesome, thanks for coming through on this!

@mtozlu
Copy link

mtozlu commented Sep 4, 2015

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.

@botularius
Copy link

+1

1 similar comment
@fabn
Copy link

fabn commented Feb 17, 2016

+1

@neohunter
Copy link

+1

@jimryan
Copy link
Contributor

jimryan commented Mar 24, 2017

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

@bastengao
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests