Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

This gem is very useful to handle static lists (like enumerations).

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 test
Octocat-spinner-32 .document
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Gemfile.lock
Octocat-spinner-32 LICENSE.txt
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 VERSION
Octocat-spinner-32 static_list.gemspec

Static List

This module is very useful to handle static lists (like enumerations).

The problem:

In your application you may want to handle things in your User model like sex (female, male) or other static lists. You want these lists to be handled using 'textual keys' in your application but stored in your database using codes in an integer column. You don't want to join other tables to display these information. You want these lists to be easily ordered, localized and translated using Rails i18n. You want view helpers to display these lists localized and validations helpers to validate the values in the 'receiving' model.

Example :

(I want to store the hair color of the user...)


class HairColor
  include StaticList::Model
  static_list [[:white, 1], [:blond, 2], [:red, 3], [:light_brown, 4], [:brown, 5], [:black, 6], [:colored, 7], [:bald, 8]]


class User < ActiveRecord::Base
  include StaticList::Validate

  validates_static_list_value :hair_color, HairColor, :allow_blank => true


module ApplicationHelper
  include StaticList::Helpers


<%= :hair_color, static_list_select_options(HairColor) %>


<%= t_static_list(@user.hair_color, HairColor) %>


  white: white
  blond: blond
  red: red


  white: blancs
  blond: blonds
  red: rouges


Copyright © 2010-2011 Novelys. See LICENSE.txt for details.


Something went wrong with that request. Please try again.