# Validate your forms with a table-less model

**URL:** <https://www.ruby-forum.com/t/validate-your-forms-with-a-table-less-model/65173>\
**Category:** Rails\
**Created:** [August 16, 2006, 5:14pm UTC](https://www.ruby-forum.com/t/validate-your-forms-with-a-table-less-model/65173 "2006-08-16T17:14:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [August 16, 2006, 5:14pm UTC](https://www.ruby-forum.com/t/validate-your-forms-with-a-table-less-model/65173/1 "2006-08-16T17:14:53Z")

</div>

Ive followed this example of how to validate a form with a tableless  
model:

[http://rails.techno-weenie.net/tip/2005/11/19/validate\_your\_forms\_with\_a\_table\_less\_model](http://rails.techno-weenie.net/tip/2005/11/19/validate_your_forms_with_a_table_less_model)

Ive got this example working but when validation fails the failed boxes  
are not highlighted in red. At the moment i have a contact details form  
and want to validate the information entered by the user but this will  
just result in sending an email, its not saving to a database table.

My code in the controller is this at the moment and this works but if  
the validation fails it just displays the flash message i have provided,  
not highlighting the boxes in red.

def contact  
@contact = Contact.new(params[:contact])  
if @contact.valid?  
OrderMailer::deliver\_send\_an\_email() # notice the ‘deliver\_’  
prefix  
flash[:notice] = ‘Query was successfully created.’  
redirect\_to :action =\> ‘contactus’  
else  
flash[:notice] = ‘Query was not successfully created.’  
redirect\_to :action =\> ‘contactus’  
end  
end

This my contacts model class:

class Contact \< ActiveRecord::Base  
def self.columns() @columns ||= []; end  
def self.column(name, sql\_type = nil, default = nil, null = true)  
columns \<\< ActiveRecord::ConnectionAdapters::Column.new(name.to\_s,  
default, sql\_type.to\_s, null)  
end  
column :name, :string  
column :contact\_details, :string  
column :subject, :string  
column :query, :string  
validates\_presence\_of :name, :contact\_details, :query  
end

Can anyone help me please?

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [November 22, 2006, 9:54pm UTC](https://www.ruby-forum.com/t/validate-your-forms-with-a-table-less-model/65173/2 "2006-11-22T21:54:28Z")

</div>

I have a similar problem. Model validation seems to work fine, but my  
error object is empty, so the errors don’t get displayed i dont know  
why. I dont have any errors.

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [November 22, 2006, 10:27pm UTC](https://www.ruby-forum.com/t/validate-your-forms-with-a-table-less-model/65173/3 "2006-11-22T22:27:32Z")

</div>

Pabloz wrote:

> I have a similar problem. Model validation seems to work fine, but my  
> error object is empty, so the errors don’t get displayed i dont know  
> why. I dont have any errors.

ok, i got it…i used redirect instead of render. rookie mistake ( cause  
i am a rookie 🙂 )

---

<div class="post-metadata">

**Author:** ![johnnybutler7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johnnybutler7](https://www.ruby-forum.com/u/johnnybutler7)\
**Post date:** [November 23, 2006, 12:27pm UTC](https://www.ruby-forum.com/t/validate-your-forms-with-a-table-less-model/65173/4 "2006-11-23T12:27:36Z")

</div>

If you want to avoid cluttering your model definitions, you can use my  
plugin:

[http://svn.viney.net.nz/things/rails/plugins/active\_record\_base\_without\_table/](http://svn.viney.net.nz/things/rails/plugins/active_record_base_without_table/)  
[http://svn.viney.net.nz/things/rails/plugins/active\_record\_base\_without\_table](http://svn.viney.net.nz/things/rails/plugins/active_record_base_without_table)  
-Jonathan
