Forum: Ruby on Rails How to override generated in validation html code?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Tomasz K. (Guest)
on 2006-03-26 19:34
Hi,
I would like to ask how to override validation functionality in RoR?
In active_record_helper.rb class there is "hardcoded" default html
generated durning validation.
If I will use
{code:ruby}
validates_presence_of :summary, :description
{code}
in my model class, there is html generated:
{code:html}
<div class="errorExplanation" id="errorExplanation"><h2>2 errors
prohibited this issue from being saved</h2><p>There were problems with
the following fields:</p><ul><li>Summary can't be
blank</li><li>Description can't be blank</li></ul></div>
{code}
I would like to change standard functionality and just have validation
message next to input field.

What is the best approach to do this?

Best regards,
Tomek
Tomasz K. (Guest)
on 2006-03-26 20:22
Hi,

It is me again. What I have done so far...

In the environment.rb I have added lines
{code:ruby}
ActionView::Base.field_error_proc = Proc.new {|html_tag, instance|
%(<div class="field-with-errors">#{html_tag}</div>)}

ActionView::Base.field_error_proc = Proc.new {|html_tag, instance|
%(<div class="field-with-errors">#{html_tag}</div>)}

module ActionView
  module Helpers
    module ActiveRecordHelper
      def error_messages_for(object_name, options = {})

      end
    end
  end
end
{code}
It ovverides standard functionality. But unfortunatly I don't know how
to exten field_error_proc to have full validation message.

Best regards,
Tomek
This topic is locked and can not be replied to.