Tomasz Korzeniowski
2006-Mar-26 15:34 UTC
[Rails] How to override generated in validation html code?
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
--
Posted via http://www.ruby-forum.com/.
Tomasz Korzeniowski
2006-Mar-26 16:22 UTC
[Rails] Re: How to override generated in validation html code?
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
--
Posted via http://www.ruby-forum.com/.