double layer of AJAX ?

Is it possible or easy to have a double layer of ajax ?

1. Basicaly there is a page that is rendered where you can delete
objects by marking them with a check box. When you click delete all
marked, it deletes those objects and updates the page with ajax.

2 part 1 above is followed by another section where if you click on
"update" it displays a upload form through ajax for acts_as_attachment
where the user can browse for a file to upload.

1 & 2 are both ajax, but after 2 runs it has to redisplay the page. If
there was another ajax layer that rendered both 1 & 2, and 1 & 2 where
also ajax, then the ajax would have 2 layers. Is that possible or easy
to do ?

If I understand you correctly, you want to reload the page after
completing the file upload, right? That's what RJS is for. RJS is a
way of sending javascript commands back to the browser as the response
of an Ajax request, which then gets executed by the browser instead of
displayed as html.

You can create a template with extension .rjs, for example
'upload.rjs' which is rendered after the uplaod action is complete and
redirect back to the original page. This file should look something
like this:

page.redirect :controller=>'some_controller', :action=>'show', :id=>@some_model

Cheers,
max

I have some ajax working, and it renders part of the page. What I
really am asking is:

say you have a page A that partially renders B so that A does not
refresh when the action for B is invoked. However now you have C.
C is either part of B or B and C are part of something else. When the
action for C is invoked which is a acts_as_attachment new. It renders C
without refreshing B. This rendering of C shows an upload form. After
the upload occurs another refresh would happen which would refresh B
and C but not A. It's a little complex and that's the best I can
explain it. I'm a little confused about it myself ...

wbsurfver wrote:

I have some ajax working, and it renders part of the page. What I
really am asking is:

say you have a page A that partially renders B so that A does not
refresh when the action for B is invoked. However now you have C.
C is either part of B or B and C are part of something else. When the
action for C is invoked which is a acts_as_attachment new. It renders C
without refreshing B. This rendering of C shows an upload form. After
the upload occurs another refresh would happen which would refresh B
and C but not A. It's a little complex and that's the best I can
explain it. I'm a little confused about it myself ...

State it again in terms of what a user would perceive.

(That technique is the power behind Use Cases...)

Ok, there is a main page, call it A. On this page there is a set of
pictures (call this B) you can mark each picture for delete with check
boxes and click a delete which will delete them and update the page so
that only B is refreshed by removing the deleted pictures and re
rendering B without rendering A. Then there is another section (call
that C). Here there is a link that says "upload picture". This is done
because acts_as_attachement seems to work in that first there is a call
to new() to create an item in the controller. so you click "upload
picture" which calls new(), new() renders a new ajax through C without
refreshing A or B. Now instead of seeing "upload picture" as a link,
you see a browser form where you can select an image from the disk.
This was rendered without refreshing A or B and is how
acts_as_attachment works from examples I have followed. Next when you
send the image back to the controller that you selected in the browser
it's through a create() call as acts_as_attachment works. After the
create call, my code refreshes the whole page A,B, and C. I want it to
just refresh B and C.

You cannot do file uploads via ajax. That being said , you can do what looks like ajax file uploads by targeting the upload form to submit to a hidden iframe on the page. But then responding back from the upload controller without refreshing the entire page is hard because whatever you return from the upload action goes to the iframe where the upload was sent thru. So you need a plugin called respond_to_parent that will let you send an rjs response back to the iframe that will get eval'd in the parent window so you can refresh just a small part of the page.

  Phew! confused yet?

http://sean.treadway.info/svn/plugins/responds_to_parent/README

Cheers-
-- Ezra Zygmuntowicz-- Lead Rails Evangelist
-- ez@engineyard.com
-- Engine Yard, Serious Rails Hosting
-- (866) 518-YARD (9273)