Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Simple, ActiveModel-compliant models.
Ruby JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
test Allowing an attribute and its validations to be set at the same time
.gitignore Add Gemfile.lock to the ignored list
.travis.yml Add Travis config
Gemfile Move to bundler-style gem structure
MIT-LICENSE Committing files (enginex gem) Testing post-receive hook when editing a file directly in GitHub
Rakefile Renamed to modest_model to prevent conflict with an existing simple_m…

ModestModel Build Status


Inspired by Crafting Rails Applications, ModestModel provides an ActiveModel-compliant class that allows you to quickly create simple, table-less models. The intended use is to back interactions with external APIs with Ruby-friendly models rather than raw structured data (such as hashes).

Notice: we're extending ModestModel's features significantly to give developers more flexibility and freedom when working with table-less models. Some of the upcoming features include:

  • ActiveRecord support: including simple delegation of methods like save and destroy, associations (has_many, belongs_to and friends) and other commonly used ActiveRecord features
  • Basic objects: to make working with simple key/value data sets easier and friendlier (think of a blend of a Hash and a Struct bundled with a collection of helpful methods)


json ='/some/path.json')
attributes_hash = JSON.decode(json)

# => {'name' => 'Michael', 'email' => ''}

class SampleModel < ModestModel::Base
  attributes :name, :email

# => #<SampleModel @name="Michael"...


ModestModel has been tested and works on MRI 1.8.7 and 1.9.2.


gem install modest_model


gem 'modest_model'


Similar to ActiveRecord models, simply create a class which inherits from ModestModel::Base. You'll need to define some attributes - this is achieved by calling the attributes method passing in the attribute names you require:

class SampleModel < ModestModel::Base
  attributes :name, :email


ModestModel includes the following ActiveModel modules:

  • ActiveModel::Conversion
  • ActiveModel::Naming
  • ActiveModel::Translation
  • ActiveModel::Serialization
  • ActiveModel::Validations
  • ActiveModel::AttributeMethods

These allow your ModestModel models to act almost the same as an ActiveRecord model, but without the database. You can mass-assign attributes, add validations, add translations, and call familiar methods like model_name.human and to_json.

ModestModel was extracted from the Mail Form gem described in chapter 2, "Building Models with Active Model", of Crafting Rails Applications by Jose Valim. This chapter therefore provides an excellent in-depth explanation of the inner workings of ModestModel.


This code has been derived from Crafting Rails Applications by Jose Valim, so all credit goes to Jose and Plataforma for granting permission to release this gem.

Something went wrong with that request. Please try again.