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
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?