In controller.rb:
def create
begin
@client = Client.new(params[:client])
# Catch the exception from AR::Base
rescue ActiveRecord::MultiparameterAssignmentErrors => ex
# Iterarate over the exceptions and remove the invalid field components from the input
ex.errors.each { |err| params[:client].delete_if { |key, value| key =~ /^#{err.attribute}/ } }
# Recreate the Model with the bad input fields removed
@client = Client.new(params[:client])
end
if @client.save
flash[:notice] = 'Client was successfully created.'
redirect_to :action => 'list'
else
init_client_lookup_tables
render :action => 'new'
end
end
In model.rb:
validates_presence_of :date_field_name, :message => 'must be a valid date'