# Forms without a database backend

**URL:** <https://www.ruby-forum.com/t/forms-without-a-database-backend/164102>\
**Category:** Rails\
**Created:** [March 27, 2009, 10:06pm UTC](https://www.ruby-forum.com/t/forms-without-a-database-backend/164102 "2009-03-27T22:06:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![devbanana](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8e8cbc/32.png) [@devbanana](https://www.ruby-forum.com/u/devbanana)\
**Post date:** [March 27, 2009, 10:06pm UTC](https://www.ruby-forum.com/t/forms-without-a-database-backend/164102/1 "2009-03-27T22:06:51Z")

</div>

Hi,

I’m trying to create a simple contact form. It might use the database  
later  
for storing the messages, but not yet, I don’t think. However, I’d still  
like to be able to validate the fields easily, like you would with  
ActiveRecord.

How can I do this? I’m new to rails so really don’t know where to start.

Thanks,  
Brandon

---

<div class="post-metadata">

**Author:** ![devbanana](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8e8cbc/32.png) [@devbanana](https://www.ruby-forum.com/u/devbanana)\
**Post date:** [March 27, 2009, 10:12pm UTC](https://www.ruby-forum.com/t/forms-without-a-database-backend/164102/2 "2009-03-27T22:12:11Z")

</div>

On Fri, Mar 27, 2009 at 4:05 PM, Brandon O.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m trying to create a simple contact form. It might use the database later  
> for storing the messages, but not yet, I don’t think. However, I’d still  
> like to be able to validate the fields easily, like you would with  
> ActiveRecord.
> 
> How can I do this? I’m new to rails so really don’t know where to start.

You can validate an ActiveRecord object using valid?.

[http://api.rubyonrails.org/classes/ActiveResource/Validations.html#M000832](http://api.rubyonrails.org/classes/ActiveResource/Validations.html#M000832)

This will ensure any model validation you include are ran.

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)

---

<div class="post-metadata">

**Author:** ![devbanana](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8e8cbc/32.png) [@devbanana](https://www.ruby-forum.com/u/devbanana)\
**Post date:** [March 27, 2009, 10:17pm UTC](https://www.ruby-forum.com/t/forms-without-a-database-backend/164102/3 "2009-03-27T22:17:27Z")

</div>

> 832
> 
> This will ensure any model validation you include are ran.

Thanks, but should I create an ActiveRecord model even though it  
shouldn’t  
be associated with a table?

Brandon

---

<div class="post-metadata">

**Author:** ![devbanana](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8e8cbc/32.png) [@devbanana](https://www.ruby-forum.com/u/devbanana)\
**Post date:** [March 27, 2009, 10:19pm UTC](https://www.ruby-forum.com/t/forms-without-a-database-backend/164102/4 "2009-03-27T22:19:49Z")

</div>

On Fri, Mar 27, 2009 at 4:16 PM, Brandon O.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks, but should I create an ActiveRecord model even though it shouldn’t  
> be associated with a table?

It would probably be the easiest way to get to the model validations.

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)

---

<div class="post-metadata">

**Author:** ![devbanana](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/8e8cbc/32.png) [@devbanana](https://www.ruby-forum.com/u/devbanana)\
**Post date:** [March 28, 2009, 12:56am UTC](https://www.ruby-forum.com/t/forms-without-a-database-backend/164102/5 "2009-03-28T00:56:08Z")

</div>

Have a look at the activerecord\_base\_without\_table plugin:  
[http://agilewebdevelopment.com/plugins/activerecord\_base\_without\_table](http://agilewebdevelopment.com/plugins/activerecord_base_without_table).  
It’s very simple and I use it a lot in my projects. However, if you  
ever get into a situation that the framework does a  
‘describe’ ( DESC ) on it, it will fail. Therefore, I modified the  
plugin to set the table name to “dual”. Works like a charm!
