# Error Handling on Ajax pages

**URL:** <https://www.ruby-forum.com/t/error-handling-on-ajax-pages/110369>\
**Category:** Rails\
**Created:** [July 25, 2007, 8:49pm UTC](https://www.ruby-forum.com/t/error-handling-on-ajax-pages/110369 "2007-07-25T20:49:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarcS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/54ee81/32.png) [@MarcS](https://www.ruby-forum.com/u/MarcS)\
**Post date:** [July 25, 2007, 8:49pm UTC](https://www.ruby-forum.com/t/error-handling-on-ajax-pages/110369/1 "2007-07-25T20:49:53Z")

</div>

Hi,

I’m having a problem with displaying errors on an Ajax page.  
On the page users can upload images and when an image is uploaded it  
will be added to the list of already uploaded images using

page.insert\_html :bottom, “assets”, :partial =\> ‘assets/  
list\_item’, :object =\> asset

The problem is that I don’t really know how to display error messages  
that occurred while uploading images (i.e. file to large, wrong  
content type)

What I did right now is insert this in my controller

```
  if @asset.save
    .......
  else
      format.js do
      responds_to_parent do
        render :update do |page|
          @asset.errors.each do |e|
              page.notify :error, e[0]+" "+e[1]
          end
        end
      end
    end

```

page.notify will then display the error message at the top of the  
page.

While this is working I would think that there’s gotta be a prettier  
way of doing this. Is there?

Marc

---

<div class="post-metadata">

**Author:** ![MarcS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/54ee81/32.png) [@MarcS](https://www.ruby-forum.com/u/MarcS)\
**Post date:** [July 25, 2007, 11:05pm UTC](https://www.ruby-forum.com/t/error-handling-on-ajax-pages/110369/2 "2007-07-25T23:05:19Z")

</div>

I’m using the:  
page.replace\_html :some\_your\_error\_div\_id, error\_messages\_for(:image)
