Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

settingsdb

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

settingsdb

  • 1.0.6
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

= SettingsDB-Rails

SettingsDB provides an easy to use mechanism for keeping application settings in your database. It also provides a namespacing mechanism to keep settings from different areas separate, as well as a defaults option.

== Getting Started

Add settingsdb-rails to your Gemfile:

gem 'settingsdb-rails'

To install the model, migration, and defaults initializer:

rails generate settingsdb:install rake db:migrate

This will create a settings model, migration, and initializer file. Now just reference settings in your code:

<% title Setting[:site_title] %>

To create a new setting just set its value:

Setting[:site_title] = "My Awesome Site!"

Non-qualified key operations use the :default namespace, to set a key in a particular namespace:

Setting[:myplugin, :site_title] = "My Awesome Plugin Site!"

To set application defaults, use SettingsDB::Defaults:

SettingsDB::Defaults[:site_title] = 'Untitled' SettingsDB::Defaults[:myplugin, :site_title] = 'Untitled Plugin'

Or use a block:

SettingsDB::Defaults.config do |c| c[:site_title] = 'Untitled' c[:myplugin, :site_title] = 'Untitled Plugin' end

You can also store rails settings in the database to make your application more configurable from the web interface. Add this to your +config/initializer/settingsdb.rb+ file:

Setting.where(:namespace => :rails).each do |setting| if AppName::Application.config.respond_to?("#{setting.name}=") AppName::Application.config.send("#{setting.name}", setting.value) end end

This assumes your appname is AppName, and that you keep rails settings separated in it's own namespace (+:rails+, in this example)

FAQs

Package last updated on 06 Jun 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc