• Stars
    star
    115
  • Rank 305,850 (Top 7 %)
  • Language
    Ruby
  • License
    MIT License
  • Created almost 14 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Rails gem for storing app configuration data in your database, with a config file to fall back on.

Configurable Build Status

A Rails 4 configuration engine. An update to Behavior for Rails 4.

How it works

Configurable lets you define app-wide configuration variables and values in config/configurable.yml. These can then be accessed throughout your app.

If you or your app users need to change these variables, Configurable stores new values in the database.

Installation

Configurable is available as a Ruby gem. Simply add it to your Rails 4 app's Gemfile:

gem 'configurable_engine'

Then run the configurable_engine:install generator:

$ rails generate configurable_engine:install

this will

  • add config/configurable.yml
  • create a migration for your configurable table
  • mount the UI in your routes (defaulting to admin/configurables)

Usage

There are two parts to how configurable_engine works. First of all there is a config file, config/configurable.yml. This file controls the variables that are allowed to be set in the app.

For example, if you wanted to have access to a config variable site_title, put this in configurable.yml:

site_title:
  name: Site Title
  default: My Site
  # type: String is the default

Now, within your app, you can access Configurable[:site_title] (or Configurable.site_title if you prefer).

Since Configurable is an ActiveRecord model, if you want to update the config, create a Configurable record in the database:

Configurable.create!(:name => 'site_title', :value => 'My New Site')

You can set the type attribute to boolean, decimal,integer, or list and it will treat those fields as those types. Lists are comma and/or newline delimeted arrays of strings.

Web Interface

Configurable comes with a web interface that is available to your app straight away at http://localhost:3000/admin/configurable.

If you want to add a layout, or protect the configurable controller, create app/controllers/admin/configurables_controller.rb as such:

$ bundle exec rails generate controller admin/configurables

include ConfigurableEngine::ConfigurablesController, eg.

class Admin::ConfigurablesController < ApplicationController
  # include the engine controller actions
  include ConfigurableEngine::ConfigurablesControllerMethods

  # add your own filter(s) / layout
  before_filter :protect_my_code
  layout 'admin'
end

and replace

route 'mount ConfigurableEngine::Engine, at: "/admin/configurable", as: "configurable"'

with

namespace :admin do
  resource :configurable, only: [:show, :update]
end

To ensure text areas are rendered correctly, ensure that your layout preserves whitespace. In haml, use the ~ operator

  %container
    ~ yield

If you want to control how the fields in the admin interface appear, you can add additional params in your configurable.yml file:

site_title:
  name: Name of Your Site   # sets the edit label
  default: My Site          # sets the default value
  type: string              # uses input type="text"
site_description:
  name: Describe Your Site  # sets the edit label
  default: My Site          # sets the default value
  type: text                # uses textarea
secret:
  name: A Secret Passphrase # sets the edit label
  default: passpass         # sets the default value
  type: password            # uses input type="password"

Value:
  name: A number            # sets the edit label
  default: 10               # sets the default value
  type: integer             # coerces the value to an integer

Price:
  name: A price             # sets the edit label
  default: "10.00"          # sets the default value
  type: decimal             # coerces the value to a decimal

Caching

If you want to use rails caching of Configurable updates, simply set

config.use_cache = true

in your config/application.rb (or config/production.rb)

Styling the interface

To style the web interface you are advised to use Sass. Here's an example scss file that will make the interface bootstrap-3 ready:

@import 'bootstrap';

.configurable-container {
  @extend .col-md-6;

  .configurable-options {
    form {
      @extend .form-horizontal;

      .configurable {
        @extend .col-md-12;
        @extend .form-group;

        textarea, input[type=text], input[type=password] {
          @extend .form-control;
        }
      }

      input[type=submit] {
        @extend .btn;
        @extend .btn-primary;
      }
    }
  }
}

Just save this into your rails assets and you're ready to go.

Running the Tests

The tests for this rails engine are in the spec and features directories. They use the dummy rails app in spec/dummy

From the top level run:

$ bundle exec rake app:db:schema:load
$ bundle exec rake app:db:test:prepare
$ bundle exec rake

Contributing

All contributions are welcome. Just fork the code, ensure your changes include a test, ensure all the current tests pass and send a pull request.

Copyright

Copyright (c) 2011 Paul Campbell. See LICENSE.txt for further details.

More Repositories

1

eyeballs.js

A lightweight MVC framework for building fast, tidy javascript web apps
JavaScript
335
star
2

whenever.js

A nice little library for writing and implementing web application behavior in javascript that looks like English.
JavaScript
284
star
3

paths_of_glory

An achievement system generator for Rails
Ruby
78
star
4

stuffing

A Rails plugin to read and write CouchDB documents via Activerecord
Ruby
53
star
5

behavior

A library for storing Rails app configuration in the database
Ruby
20
star
6

twitter2campfire

Publish a Summize Twitter search feed to Campfire
Ruby
20
star
7

paulconf

19
star
8

realex

A Ruby class for interfacing with www.realexpayments.com
Ruby
19
star
9

shortcode-url

A really simple Rails plugin to generate a unique code on a field for TinyURL style URLS
Ruby
14
star
10

merge_translation

A plugin to merge YAML translation files in Rails 2.2
Ruby
12
star
11

url_field

A simple ActiveRecord plugin to correctly format a URL in the database whether the user enters "http://" or not
Ruby
12
star
12

shakespeare

A simple drop-in CMS for Rails
Ruby
10
star
13

formatted-dates

A simple acts_as style plugin for easily formatting of dates within Rails models
Ruby
10
star
14

address_engine

Ruby
9
star
15

phone_codes

International phone dialling codes for options_for_select
Ruby
8
star
16

town-crier

Sends a message to Twitter every hour.
Ruby
6
star
17

cukemin

A Rails Admin Controller / View Scaffold Generator that eschews specs in favour of cukes and is cut exactly to my liking.
Ruby
6
star
18

ruby-ireland-23-sept-2014

5
star
19

can_has

A simple ActiveRecord plugin to add a lovely little can_view, can_edit, can_delete permissions system in simple use cases
5
star
20

meview

A sample eyeballs.js localstorage web app
JavaScript
5
star
21

neofuturists_presenter

Ruby
4
star
22

big_decimal_price

BigDecimal.new('10.9').to_s #=> '10.90'
Ruby
4
star
23

kalipso

Ruby
4
star
24

couchy

A simple HTML template -> CouchDB document translator
Ruby
4
star
25

design-article-site

HTML/CSS to go along with an article I wrote for dotMobi
JavaScript
4
star
26

feelings

A tumble-log written in Rails using CouchDB as a data-store
Ruby
4
star
27

audit

A Rails plugin to save changes to an ActiveRecord model
Ruby
3
star
28

exceptional-php

PHP Client for geteceptional.com
PHP
3
star
29

ruby-ireland-schedule-app

Ruby
3
star
30

eyeballs_rails

Rails helpers for eyeballs.js
Ruby
2
star
31

couchpop

Upload a directory to CouchDB
Ruby
2
star
32

whenever.js-lightning-talk

a lightning talk about http://github.com/paulca/whenever.js
Ruby
2
star
33

paul-is-awesome

Ruby
2
star
34

paulca.github.com

2
star
35

blog-example

Ruby
1
star
36

uninitialized_constant_example

Example of Rails 3 bug
Ruby
1
star
37

jaysus

Local / Remote persistence for JSON APIs / Local Store
Ruby
1
star
38

ruby-ireland-schedule-api

Ruby
1
star
39

rails31rubyireland

Presentation to Ruby Ireland on August 30 for Rails 3.1 release party!
Ruby
1
star
40

db_context

Simple Rails plugin for switching context to a different database
Ruby
1
star
41

ubimport

Ruby
1
star
42

sanity-nuxt-events

Events with Nuxt.js
Vue
1
star
43

ucd-rails-intro

Ruby
1
star