hi all, while creating a new row in a table called Employee if i enter wron inputs the error page comes likes this. 11 errors prohibited this employee from being saved There were problems with the following fields: * Username can''t be blank * Phoneno is not a number * Phoneno is too short (minimum is 8 characters) * Lastname can''t be blank * Firstname is too short (minimum is 5 characters) * Firstname can''t be blank * Emailid is invalid * Emailid can''t be blank * Password is too short (minimum is 5 characters) * Password can''t be blank * Please select a Role out of this content i want to edit the "{ 11 errors prohibited this employee from being saved There were problems with the following fields: }" part.how to do it.people knows it please help me. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi, just override the default helper. here''s the source (ie put this in your helper, and then change it to fit) def error_messages_for(*params) options = params.extract_options!.symbolize_keys if object = options.delete(:object) objects = [object].flatten else objects = params.collect {|object_name| instance_variable_get("@#{object_name}") }.compact end count = objects.inject(0) {|sum, object| sum + object.errors.count } unless count.zero? html = {} [:id, :class].each do |key| if options.include?(key) value = options[key] html[key] = value unless value.blank? else html[key] = ''errorExplanation'' end end options[:object_name] ||= params.first options[:header_message] = "#{pluralize(count, ''error'')} prohibited this #{options[:object_name].to_s.gsub(''_'', '' '')} from being saved" unless options.include?(:header_message) options[:message] ||= ''There were problems with the following fields:'' unless options.include?(:message) error_messages = objects.map {|object| object.errors.full_messages.map {|msg| content_tag(:li, msg) } } contents = '''' contents << content_tag(options[:header_tag] || :h2, options[:header_message]) unless options[:header_message].blank? contents << content_tag(:p, options[:message]) unless options[:message].blank? contents << content_tag(:ul, error_messages) content_tag(:div, contents, html) else '''' end end Julian Learn Ruby on Rails! Check out the FREE VIDS (for a limited time) VIDEO #3 out NOW! http://sensei.zenunit.com/ On 10/04/2008, at 3:22 PM, Karthikragunath Bhavani wrote:> > > > hi all, > > while creating a new row in a table called Employee if i enter > wron inputs the error page comes likes this. > > > > 11 errors prohibited this employee from being saved > > There were problems with the following fields: > > * Username can''t be blank > * Phoneno is not a number > * Phoneno is too short (minimum is 8 characters) > * Lastname can''t be blank > * Firstname is too short (minimum is 5 characters) > * Firstname can''t be blank > * Emailid is invalid > * Emailid can''t be blank > * Password is too short (minimum is 5 characters) > * Password can''t be blank > * Please select a Role > > > out of this content i want to edit the > > > "{ 11 errors prohibited this employee from being saved > > There were problems with the following fields: }" part.how to do > it.people knows it please help me. > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
hi julian i tried with ur code but the code stuck in second line itself.i pasted the code in helper.rb as you said but im getting error when executing. the error is: "{ undefined method `extract_options!'' for ["valuecheck"]:Array }" here "valuecheck" => is my model''s name. im new to ror julian i dont know how to proceed with this.please help me if u know what''s wrong. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi, Here you are, some code munged to work properly. Feel free to edit it to fit as you like. Julian. Learn Ruby on Rails! Check out the FREE VIDS (for a limited time) VIDEO #3 out NOW! http://sensei.zenunit.com/ def error_messages_for(object_name) objects = [instance_variable_get("@#{object_name}")].flatten count = objects.inject(0) {|sum, object| sum + object.errors.count } options = {} unless count.zero? html = {} [:id, :class].each do |key| html[key] = ''errorExplanation'' end options[:object_name] ||= object_name options[:header_message] = "#{pluralize(count, ''error'')} prohibited this #{options[:object_name].to_s.gsub(''_'', '' '')} from being saved" unless options.include?(:header_message) options[:message] ||= ''There were problems with the following fields:'' unless options.include?(:message) error_messages = objects.map {|object| object.errors.full_messages.map {|msg| content_tag(:li, msg) } } contents = '''' contents << content_tag(options[:header_tag] || :h2, options[:header_message]) unless options[:header_message].blank? contents << content_tag(:p, options[:message]) unless options[:message].blank? contents << content_tag(:ul, error_messages) content_tag(:div, contents, html) else '''' end end On 11/04/2008, at 4:32 PM, Karthikragunath Bhavani wrote:> > > > hi julian i tried with ur code but the code stuck in second line > itself.i pasted the code in helper.rb as you said but im getting error > when executing. > > the error is: > > "{ undefined method `extract_options!'' for ["valuecheck"]:Array > }" > > here "valuecheck" => is my model''s name. > > im new to ror julian i dont know how to proceed with this.please help > me if u know what''s wrong. > > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---