# Problems with error\_messages\_for

**URL:** <https://www.ruby-forum.com/t/problems-with-error-messages-for/64438>\
**Category:** Rails\
**Created:** [January 23, 2006, 2:39pm UTC](https://www.ruby-forum.com/t/problems-with-error-messages-for/64438 "2006-01-23T14:39:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Bannister](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/90db22/32.png) [@Michael\_Bannister](https://www.ruby-forum.com/u/Michael_Bannister)\
**Post date:** [January 23, 2006, 2:39pm UTC](https://www.ruby-forum.com/t/problems-with-error-messages-for/64438/1 "2006-01-23T14:39:02Z")

</div>

I have a model Area which has\_many Streets. The Area has a couple of  
attributes of its own but mostly I want to be able to add/delete/update  
Streets for a particular Area, but all on one page rather than having a  
separate view for editing a Street. I’ve managed to get a form  
displayed with a row for each Street already assigned to the Area by  
using form fields with street[id][name], street[id][num\_houses] etc.  
But when I send the form I don’t know how to get any validation errors  
reported. Errors on Area are nicely displayed with the red outlines - I  
think this is thanks to \<%= error\_messages\_for ‘area’ %\> being included  
in the view. Can I get this to work for the multiple Street input  
fields as well?  
I’ve tried \<%= error\_messages\_for ‘street’ %\> (You have a nil object  
when you didn’t expect it! You might have expected an instance of  
ActiveRecord::Base. The error occured while evaluating nil.errors)  
and \<%= error\_messages\_for ‘street[]’ %\> (`@street[]’ is not allowed as  
an instance variable name)

def update\_area  
@area = Area.find(params[:id])  
@streets = @area.streets

```
unless params[:street].nil?
  Street.update(params[:street].keys, params[:street].values)
end

if @area.update_attributes(params[:area])
  flash[:notice] = 'Area was successfully updated.'
  redirect_to :action => 'edit_area', :id => @area
else
  render :action => 'edit_area'
end

```

end

Thanks so much in advance for any suggestions.

---

<div class="post-metadata">

**Author:** ![Michael\_Bannister](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/90db22/32.png) [@Michael\_Bannister](https://www.ruby-forum.com/u/Michael_Bannister)\
**Post date:** [January 23, 2006, 10:12pm UTC](https://www.ruby-forum.com/t/problems-with-error-messages-for/64438/2 "2006-01-23T22:12:39Z")

</div>

On Jan 23, 2006, at 6:39 AM, Michael Bannister wrote:

> outlines - I  
> think this is thanks to \<%= error\_messages\_for ‘area’ %\> being  
> included  
> in the view. Can I get this to work for the multiple Street input  
> fields as well?

error\_ messages\_for is not responsible for adding the red outlines–  
its sole purpose is to dump out the error messages associated with an  
ActiveRecord object. In fact, it is highly recommended that you use  
your own method or replace error\_messages\_for because it is so ugly  
(imho).

To answer your question, though, see [http://www.ruby-forum.com/topic/](http://www.ruby-forum.com/topic/)  
52143. The topic is closely related, and then goes off-topic a bit  
towards your direction, so keep reading.

Duane J.  
(canadaduane)  
[http://blog.inquirylabs.com/](http://blog.inquirylabs.com/)

---

<div class="post-metadata">

**Author:** ![Michael\_Bannister](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/90db22/32.png) [@Michael\_Bannister](https://www.ruby-forum.com/u/Michael_Bannister)\
**Post date:** [January 23, 2006, 11:12pm UTC](https://www.ruby-forum.com/t/problems-with-error-messages-for/64438/3 "2006-01-23T23:12:02Z")

</div>

> To answer your question, though, see [http://www.ruby-forum.com/topic/](http://www.ruby-forum.com/topic/)  
> 52143. The topic is closely related, and then goes off-topic a bit  
> towards your direction, so keep reading.

Many thanks - looks like what I’m after, and I’ll read it more  
thoroughly tomorrow! 🙂
