Hello all, I''m new to Ruby and Ruby on Rails, so please have patience with a newbie. I was looking at the HTML produced when there are form errors and realized why my layout keeps breaking. Every label and input with an error gets wrapped with a div tag! So, I''ve been looking at the source ... but I have yet to find what object or method to inherit from. Can you guys tell me how to change the output? What I''d like to accomplish is that flawed fields, any inputs, have the standard error class (no wrapping div) and that any labels have the class too. IE, I''d rather output the tag with a class name than a wrapping div with a class name. Thanks for any help you guys can give. - Robert -- 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 -~----------~----~----~----~------~----~------~--~---
On 21 Nov 2008, at 17:16, Robert Kosek wrote:> > Hello all, I''m new to Ruby and Ruby on Rails, so please have patience > with a newbie. > > I was looking at the HTML produced when there are form errors and > realized why my layout keeps breaking. Every label and input with an > error gets wrapped with a div tag! So, I''ve been looking at the > source > ... but I have yet to find what object or method to inherit from. > > Can you guys tell me how to change the output? What I''d like to > accomplish is that flawed fields, any inputs, have the standard error > class (no wrapping div) and that any labels have the class too. IE, > I''d > rather output the tag with a class name than a wrapping div with a > class > name. >You can set ActionView::Base.field_error_proc (take a look insider active_record_helper to see what the default is.) Fred> Thanks for any help you guys can give. > > - Robert > -- > 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> You can set ActionView::Base.field_error_proc (take a look insider > active_record_helper to see what the default is.) > > FredThanks Fred, just what I needed! Is the tag an object, or the actual string output? -- 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 -~----------~----~----~----~------~----~------~--~---
On 21 Nov 2008, at 17:42, Robert Kosek wrote:> > Frederick Cheung wrote: >> You can set ActionView::Base.field_error_proc (take a look insider >> active_record_helper to see what the default is.) >> >> Fred > > Thanks Fred, just what I needed! Is the tag an object, or the actual > string output?Dunno. Try it out :-) Fred> > -- > 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 -~----------~----~----~----~------~----~------~--~---
Robert Kosek wrote:> Is the tag an object, or the actual string output?Okay, here''s what I found. ActiveView::Base.field_error_proc has two parameters, the HTML output followed by the actual object itself. Then, field_error_proc is called within a function within the InstanceTag object which passes itself to the error procedure. InstanceTag is not documented, so I''m left with scrounging what I can get from the source code. Between active_record_helper.rb and form_helper.rb I have a decent reference. One problem: the error handler is not aware of the options passed to the InstanceTag. So, I cannot actually modify the class option and regenerate the tag. (Not without modifying the source, which I''m not comfortable with doing yet.) So... gsub here I come. Here''s what I have: ----- # I put this in the top of application.rb, where should it go? ActionView::Base.field_error_proc = Proc.new do |html, instance_tag| if html.match(/class=(\''|\")([\w\s\d]*?)\1/i) html.gsub(/class=(\''|\")([\w\s\d]*?)\1/i, ''class="\2 fieldWithErrors"'') else html.gsub(/\<[\w]+/i, ''\0 class="fieldWithErrors"'') end end yields: <input class="fieldWithErrors" <input class="myClass fieldWithErrors" -- 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 -~----------~----~----~----~------~----~------~--~---