Hi, I used the below syntax in config/initializers, but i am getting the error message two times, please suggest me the better way to over come it ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| if html_tag =~ /<(input|label|textarea|select)/ error_class = ''error'' nodes = Hpricot(html_tag) nodes.each_child { |node| node[:class] node.classes.push(error_class).join('' '') unless !node.elem? || node[:type] == ''hidden'' || node.classes.include?(error_class) } nodes.to_html else html_tag end end -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I am using validations for first name, but I am getting error message two times for the label and text_field, <div class="field"> <%= f.label :first_name %> <%= f.text_field :first_name %> </div> -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 17 January 2012 08:56, Kapil Kaligotla <kapil.kaligotla-C8lSLueJBA4oM3ANB2zruQ@public.gmane.org> wrote:> I am using validations for first name, but I am getting error message > two times for the label and text_field, > > <div class="field"> > <%= f.label :first_name %> > <%= f.text_field :first_name %> > </div>Show us the validation you have specified and what the error is and why you think the error is wrong. Otherwise what hope have we got of helping? Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
In my model i had used the validation validates :first_name, :format => {:with => /^[a-zA-Z.\s]*$/ i}, :length => {:minimum => 1, :maximum => 25}, :presence => true in views <div class="field"> <%= f.label :first_name %> <%= f.text_field :first_name %> </div> in the browser i am getting error messages 2 times like this First name is too short (minimum is 1 characters),can''t be blank is too short (minimum is 1 characters),can''t be blank On Jan 17, 3:20 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 17 January 2012 08:56, Kapil Kaligotla > > <kapil.kaligo...-C8lSLueJBA4oM3ANB2zruQ@public.gmane.org> wrote: > > I am using validations for first name, but I am getting error message > > two times for the label and text_field, > > > <div class="field"> > > <%= f.label :first_name %> > > <%= f.text_field :first_name %> > > </div> > > Show us the validation you have specified and what the error is and > why you think the error is wrong. Otherwise what hope have we got of > helping? > > Colin-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 17 January 2012 11:20, Kapil Kaligotla <kapil.kaligotla-C8lSLueJBA4oM3ANB2zruQ@public.gmane.org> wrote:> In my model i had used the validation > > validates :first_name, :format => {:with => /^[a-zA-Z.\s]*$/ > i}, :length => {:minimum => 1, :maximum => 25}, :presence => true > > in views > <div class="field"> > <%= f.label :first_name %> > <%= f.text_field :first_name %> > </div> > > in the browser i am getting error messages 2 times like this > > > First name is too short (minimum is 1 characters),can''t be blank > is too short (minimum is 1 characters),can''t be blankThat suggests that the name is blank by the time it gets to be saved in the database. First have a look in the log (log/development.log) and check that the name is passed in correctly. Then have a look at the Rails Guide on debugging. It will show you how to use ruby-debug to break into your code and inspect data so that you can see what is wrong. By the way please do not top post, it makes it difficult to follow the thread. Insert your reply at appropriate points in the previous message. Thanks. Colin> > > > > On Jan 17, 3:20 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> On 17 January 2012 08:56, Kapil Kaligotla >> >> <kapil.kaligo...-C8lSLueJBA4oM3ANB2zruQ@public.gmane.org> wrote: >> > I am using validations for first name, but I am getting error message >> > two times for the label and text_field, >> >> > <div class="field"> >> > <%= f.label :first_name %> >> > <%= f.text_field :first_name %> >> > </div> >> >> Show us the validation you have specified and what the error is and >> why you think the error is wrong. Otherwise what hope have we got of >> helping? >> >> Colin > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- gplus.to/clanlaw -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Tue, Jan 17, 2012 at 3:20 AM, Kapil Kaligotla <kapil.kaligotla-C8lSLueJBA4oM3ANB2zruQ@public.gmane.org> wrote:> validates :first_name, :format => {:with => /^[a-zA-Z.\s]*$/ > i}, :length => {:minimum => 1, :maximum => 25}, :presence => trueYour format regex will pass an empty string (""), or a string of nothing but space characters, so that''s pointless. Alternatively, if you check for at least one valid word character, then the name must be present and must be at least 1 character long. (I''m not sure why you have either the \s or . in there.) If you''ve specified a minimum length of 1, then the :presence check is also pointless, isn''t it? You could condense this whole thing into one regular expression, which would likely give you only one error message :-) e.g. /\A\s*[a-zA-Z]{1,25}\s*\Z/ Aside: You might also want to reconsider your requirements -- for example "D''Arcy" is a legitimate first name :-) HTH, -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.