Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Bringing together the different tableless model implementations into a single gem/plugin
Branch: master
#24 Compare This branch is 91 commits ahead of kennethkalmer:master.
Failed to load latest commit information.
features Upgrade to rspec 3.1 and Appraisal 1.0
gemfiles Upgrade to rspec 3.1 and Appraisal 1.0
lib Add _create_record and _update_record methods to fake InstanceMethods…
spec Upgrade to rspec 3.1 and Appraisal 1.0
.gitignore First test is working
.rspec fix for travis
.travis.yml Fixing .travis.yml syntax atempt 2
Gemfile Ensured upper limit for certain gems on ruby 1.8
LICENSE.txt Added license file. Fixes a typo in the README
Rakefile First spec
activerecord-tableless.gemspec Upgrade to rspec 3.1 and Appraisal 1.0
init.rb Require active_record instead of activerecord to squash a rails warning

ActiveRecord Tableless

Build Status Dependency Status Code Climate

A single implementation of the ActiveRecord Tableless pattern for any Rails project or other Ruby project that uses ActiveRecord.

Why, why, why

Why would you ever consider this gem as opposed to ActiveModel.

In Rails 2 ActiveModel does not exists (this is when it all started; see History section)

In Rails 3 there is an Active Model API, where you can use some features of Active Record in other classes. Yehuda Katz has written a nice introduction about this.

In Rails 4 basic features of the Active Model API can be activated by including ActiveModel:Model in the model. Carlos Antônio has written a nice tutorial about this.

However neither the Active Model API (Rails 3) nor the ActiveModel::Model (Rails 4) supports relations and nested attributes.


ActiveRecord Tableless is distributed as a gem, which is how it should be used in your app.

Include the gem in your Gemfile:

gem "activerecord-tableless", "~> 1.0"

Supported Versions

Supported version are ActiveRecord version 2.3.x, 3.0.x series, 3.2.x series and 4.x series

You may be able to make it work with 3.1.x, but you should expect to put some time in it.


Define a model like this:

class ContactMessage < ActiveRecord::Base
  column :name, :string
  column :email, :string
  validates_presence_of :name, :email

You can now use the model in a view like this:

<%= form_for :message, @message do |f| %>
  Your name: <%= f.text_field :name %>
  Your email: <%= f.text_field :email %>
<% end %>

And in the controller:

def message
  @message =
    @message.attributes = params[:message]
    if @message.valid?
      # Process the message...

For Rails 2.3.x series you need to add this line in the top of your model file.

require 'activerecord-tableless'

If you wish (this is not recommended), you can pretend you have a succeeding database by using

has_no_table :database => :pretend_success


To start develop, please download the source code

git clone git://

When downloaded, you can start issuing the commands like

bundle install
bundle exec rake appraisal:gemfiles
bundle exec rake appraisal:install
bundle exec rake appraisal

Or you can see what other options are there:

bundle exec rake -T


Originally this code was implemented for Rails 2 by Kenneth Kalmer. For Rails 3 the need for this functionality was reduced dramatically due to the introduction of ActiveModel. But because the ActiveModel does not support relations and nested attributes the existence of this gem is still justified.

For a history of technical implementation details feel free to take a look in the git log :-)


Copyright (c) Jarl Friis. See LICENSE.txt for further details.

Something went wrong with that request. Please try again.