How to do validation with displayed error msgs

Could someone point me at an example that do validation “correctly”.

I’ve got a controller, a couple of models, and some views. They work
fine except for the validation.

My model looks like
"
class ContractPayment < ActiveRecord::Base

set_table_name “contract_payment”
set_primary_key “contract_payment_id”

belongs_to :contract, :foreign_key => “contract_id”

validates_presence_of :contract_id, :credit_card_type_code,
:credit_card_type_prefix, :credit_card_expiration_date,
:credit_card_number, :credit_card_validation_code

end
"
How do I trigger this validation and then display error msgs back to
the user?

Thanks,
Jason

You have two choices:

(1) To display all error messages use the method error_messages_for()
in your view.

(2) To separate all the error messages, use the method
error_message_on() in your view.

The methods’ details can be found here:

Zack

By the way, I was assuming that you were already doing something like:

if @contract_payment.save then
#success
else
#redirect to edit view where
#error messages will be shown
end

in your controller.

Zack