Last Updated: February 25, 2016
· chuckbutler

Active Record Models not tied to the DB

Its occasionally necessary to work with Active Record style models (See: Gems that rely heavily on AR) You can circumvent getting messy with your models by scoping them and using the AR::Lint test


Quick and Dirty version:

change your class definition as follows:

class Rockies < ActiveRecord::Base
  #Model Code

to mimic the following

   class Rockies
      include ActiveModel::Validations
      include ActiveModel::Conversion
      extend ActiveModel::Naming

      def persisted?

   #Model Code

Thats pretty much it, If your models were generated using scaffolding this will unlink your model from the database and uses the ActiveModel LINT guide for best uses, its pretty stripped down so if you find a method you need thats not implemented by default, give the official LINT file a glance and see what classes you should include/extend.