# Faking an ActiveRecord Model

**URL:** <https://www.ruby-forum.com/t/faking-an-activerecord-model/193068>\
**Category:** Rails\
**Created:** [August 10, 2010, 5:51pm UTC](https://www.ruby-forum.com/t/faking-an-activerecord-model/193068 "2010-08-10T17:51:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yankees26](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/eb9ed0/32.png) [@yankees26](https://www.ruby-forum.com/u/yankees26)\
**Post date:** [August 10, 2010, 5:51pm UTC](https://www.ruby-forum.com/t/faking-an-activerecord-model/193068/1 "2010-08-10T17:51:45Z")

</div>

I want to fake an ActiveRecord model like so… instead of having a Plan  
table in my database, I’d like to just have a variable somewhere  
(shallow example):

Plans = [{ :id =\> 1, :price =\> 9.99,  
{ :id =\> 2, :price =\> 14.99,  
{ :id =\> 3, :price =\> 19.99 }]

And then I guess I’d still like to be able to associate this with my  
User model… so User.plan[:price] brings up 9.99 or whatever. User  
belongs\_to :plan, so the User would have a plan\_id column?

Any tips? Rails 3.

Thanks!

---

<div class="post-metadata">

**Author:** ![yankees26](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/eb9ed0/32.png) [@yankees26](https://www.ruby-forum.com/u/yankees26)\
**Post date:** [August 10, 2010, 8:17pm UTC](https://www.ruby-forum.com/t/faking-an-activerecord-model/193068/2 "2010-08-10T20:17:21Z")

</div>

On Tue, Aug 10, 2010 at 8:51 AM, Joao S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> belongs\_to :plan, so the User would have a plan\_id column?
> 
> Any tips? Rails 3.

I hate to ask the obvious question here… but why not just have a  
regular model with a table behind it? What problem are you solving  
here? What problems are you introducing? Just want to make sure you’re  
factoring the tradeoffs here…

Cheers,  
Robby

–  
Robby R.  
Chief Evangelist, Partner

PLANET ARGON, LLC  
Web Design and Development with Ruby on Rails

> **[Planet Argon](https://www.planetargon.com/)**
>
> Planet Argon is a Ruby on Rails development agency specializing in maintenance and support for existing Rails apps. Based in Portland, OR, Planet Argon has been a member of the Rails community since 2004.

+1 408 372 7466  
+1 815 642 4068 [fax]

---

<div class="post-metadata">

**Author:** ![yankees26](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/eb9ed0/32.png) [@yankees26](https://www.ruby-forum.com/u/yankees26)\
**Post date:** [August 10, 2010, 9:17pm UTC](https://www.ruby-forum.com/t/faking-an-activerecord-model/193068/3 "2010-08-10T21:17:53Z")

</div>

Joao S. wrote:

> I want to fake an ActiveRecord model like so… instead of having a Plan  
> table in my database, I’d like to just have a variable somewhere  
> (shallow example):
> 
> Plans = [{ :id =\> 1, :price =\> 9.99,  
> { :id =\> 2, :price =\> 14.99,  
> { :id =\> 3, :price =\> 19.99 }]
> 
> And then I guess I’d still like to be able to associate this with my  
> User model… so User.plan[:price] brings up 9.99 or whatever. User  
> belongs\_to :plan, so the User would have a plan\_id column?
> 
> Any tips? Rails 3.

You don’t have to “fake it” anymore in Rails 3. Just implement  
ActiveModel:

> **[\#219 Active Model - RailsCasts](http://railscasts.com/episodes/219-active-model)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.
