Enum Columns - activescaffold/active_scaffold GitHub Wiki

You can use columns like enum with ActiveScaffold.

In create and update actions this will generate a select tag and into list, this will show the translated value. You can set different strings for value and label, for example storing m or f and showing male and female in the form and list. ActiveScaffold will translate only symbols, so text to show must be a symbol if you want ActiveScaffold to translate it.

config/locales/en.yml

en:
  activerecord:
    attributes:
      person:
        m: 'Male'
        f: 'Female'
# app/models/person.rb
class Person < ActiveRecord::Base
  SEX = %w(m f)
  validates_inclusion_of :sex, :in => SEX
end

# app/controllers/people.rb
class PeopleController < ApplicationController
  active_scaffold do |config|
    config.columns[:sex].form_ui = :select
    config.columns[:sex].options = {:options => Person::SEX.map(&:to_sym)}
  end
end

Setting options in config block works for static options. If different options must be used in different requests, because they depend on signed in user or other record’s columns, active_scaffold_enum_options helper may be overrided:

# app/helpers/people_helper.rb
module PeopleHelper
  def active_scaffold_enum_options(column, record)
    if column == :sex
      # return array of value, text arrays, or array of symbols
    else
      super
    end
  end
end
⚠️ **GitHub.com Fallback** ⚠️