# Editing error page content

**URL:** <https://www.ruby-forum.com/t/editing-error-page-content/134370>\
**Category:** Rails\
**Created:** [April 10, 2008, 7:22am UTC](https://www.ruby-forum.com/t/editing-error-page-content/134370 "2008-04-10T07:22:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![karthikragu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a88e57/32.png) [@karthikragu](https://www.ruby-forum.com/u/karthikragu)\
**Post date:** [April 10, 2008, 7:22am UTC](https://www.ruby-forum.com/t/editing-error-page-content/134370/1 "2008-04-10T07:22:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![karthikragu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a88e57/32.png) [@karthikragu](https://www.ruby-forum.com/u/karthikragu)\
**Post date:** [April 11, 2008, 8:32am UTC](https://www.ruby-forum.com/t/editing-error-page-content/134370/2 "2008-04-11T08:32:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![karthikragu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a88e57/32.png) [@karthikragu](https://www.ruby-forum.com/u/karthikragu)\
**Post date:** [April 10, 2008, 8:14am UTC](https://www.ruby-forum.com/t/editing-error-page-content/134370/3 "2008-04-10T08:14:57Z")

</div>

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/](http://sensei.zenunit.com/)

---

<div class="post-metadata">

**Author:** ![karthikragu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a88e57/32.png) [@karthikragu](https://www.ruby-forum.com/u/karthikragu)\
**Post date:** [April 11, 2008, 8:57am UTC](https://www.ruby-forum.com/t/editing-error-page-content/134370/4 "2008-04-11T08:57:26Z")

</div>

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/](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
