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 received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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: http://www.rubyonrails.org/api/classes/ActionView/Helpers/ActiveRecordHelper.html Zack On Dec 11, 5:06 pm, "Jason Vogel" <jasonvo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 On Dec 12, 8:11 am, "Zack McCoy" <zachary.mc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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: > > http://www.rubyonrails.org/api/classes/ActionView/Helpers/ActiveRecor... > > Zack > > On Dec 11, 5:06 pm, "Jason Vogel" <jasonvo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > 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 received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---