views:

113

answers:

1

What's the best way to create a model in Ruby on Rails that doesn't have an underlying implementation in as far as a database table goes? It's very common to write classes that perform behavior on a particular problem domain, yet can use some of the benefits that ActiveRecord has such as validation.

Is it best to just create it as a module or helper? What is the best practice here?

+6  A: 

Checkout the screencast by Ryan Bates that covers exactly this - Tableless Models.

http://railscasts.com/episodes/193-tableless-model

With this approach, your Model would still subclass ActiveRecord::Base but define the columns manually, which allows you to use ActiveRecord features such as validations, and associations without a database.

Anurag