# Render RJS and action from submit\_tag?

**URL:** <https://www.ruby-forum.com/t/render-rjs-and-action-from-submit-tag/67940>\
**Category:** Rails\
**Created:** [September 8, 2006, 2:38am UTC](https://www.ruby-forum.com/t/render-rjs-and-action-from-submit-tag/67940 "2006-09-08T02:38:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Justin\_Caldwell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3ec8ea/32.png) [@Justin\_Caldwell](https://www.ruby-forum.com/u/Justin_Caldwell)\
**Post date:** [September 8, 2006, 2:38am UTC](https://www.ruby-forum.com/t/render-rjs-and-action-from-submit-tag/67940/1 "2006-09-08T02:38:31Z")

</div>

I’m using “file column” for multiple image uploads. Sometimes it takes  
a while for the upload to complete and I would like to provide a tiny  
bit of feedback to the user while it’s uploading.

Right now I don’t need a progress bar. I’m using mongrel so don’t even  
know it that’s possible yet. Instead, I created a simple RJS template  
(my first- woo) that says “File uploading, please wait…” with an  
animated gif. Created a simple link\_to\_remote , tested it out, works  
great.

Now, when submitting the form, I can’t figure out how to call both the  
RJS template and the action in my controller. Tried render :action =\>  
‘uploadindicator’ in the action itself but get the “Can’t have multiple  
renders” which makes sense.

Played around with ‘submit\_remote\_tag’, with no luck. :loading looks  
like it only works with link\_to\_remote or form\_remote\_tag.

Any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![Justin\_Caldwell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3ec8ea/32.png) [@Justin\_Caldwell](https://www.ruby-forum.com/u/Justin_Caldwell)\
**Post date:** [September 8, 2006, 3:28am UTC](https://www.ruby-forum.com/t/render-rjs-and-action-from-submit-tag/67940/2 "2006-09-08T03:28:36Z")

</div>

Justin Caldwell wrote:

> I’m using “file column” for multiple image uploads. Sometimes it takes  
> a while for the upload to complete and I would like to provide a tiny  
> bit of feedback to the user while it’s uploading.
> 
> Right now I don’t need a progress bar. I’m using mongrel so don’t even  
> know it that’s possible yet. Instead, I created a simple RJS template  
> (my first- woo) that says “File uploading, please wait…” with an  
> animated gif. Created a simple link\_to\_remote , tested it out, works  
> great.
> 
> Now, when submitting the form, I can’t figure out how to call both the  
> RJS template and the action in my controller. Tried render :action =\>  
> ‘uploadindicator’ in the action itself but get the “Can’t have multiple  
> renders” which makes sense.
> 
> Played around with ‘submit\_remote\_tag’, with no luck. :loading looks  
> like it only works with link\_to\_remote or form\_remote\_tag.
> 
> Any help would be appreciated.

Woo! a question I can actually answer!

So here’s the deal, in order to see my answer you have to put up with a  
brief bout of Turrets syndrome specific to the so-called documentation  
in Ruby and Rails:  
  
Ruby and Rails are great but they are completely undocumented!  
A list of methods is to documentation as Al Gore is to the internet

So, what I seem to have deduced from my many failures to get similar  
things to work is the following:

1. Any, All, and Every (non-private) method in a controller must have  
one and only one and not less than one or more than one EXECUTED render  
call.

2. The controller method always gets first crack at doing the rendering.  
If it chooses not to do any, then Rails will start looking for an  
alternative. It looks for a same-named.rhtml file first, and failing  
that looks for a same-named.rjs file. Failing all that it complains in  
the log that you are a non-rendering idiot.

3. If you are doing ajaxy things, any, all, and every render (with one  
exception) must be of the “render :update” variety. Render :update is  
called in a block fashion as vaguely described in the “documentation”.  
If Rails winds up using an rjs file, it “sticks it in an imaginary  
render :update block” for execution.

Given all that, I would recommend giving your rjs file the same name as  
the controller method called out in the submit. I would then not do any  
rendering at all in your controller method. Rails will see your  
reticence to render in the controller method and fall back to looking  
for rhtml or rjs files.

An alternative would be to “render :update” your rjs file from the  
controller.

hth,  
jp

P.S. I’m a rubynuby. Sometimes I get it wrong, in which case my failure  
often provokes an expert to chime in. Either way, it all works out for  
the best.

---

<div class="post-metadata">

**Author:** ![Justin\_Caldwell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3ec8ea/32.png) [@Justin\_Caldwell](https://www.ruby-forum.com/u/Justin_Caldwell)\
**Post date:** [September 8, 2006, 11:55pm UTC](https://www.ruby-forum.com/t/render-rjs-and-action-from-submit-tag/67940/3 "2006-09-08T23:55:14Z")

</div>

Thanks for the info. I think I’m getting closer.

However, I really do want to render two things. When the files are  
uploading (beginning of method), I want to display a message  
(Uploading…) and when the files complete (method completes) I want to  
display another message (Images successfully uploaded.).

I can’t call the rjs directly because I’m uploading files with  
“:multipart =\> true” and ajax can’t handle files/images.

Played around with a hidden iframe, but can’t get around having to  
render twice.

So I’m still stumped.

BTW, I had a misprint in my original post. I said that I’ve tried the  
“render :action =\>” and meant to say “render :update =\>”.

---

<div class="post-metadata">

**Author:** ![Justin\_Caldwell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3ec8ea/32.png) [@Justin\_Caldwell](https://www.ruby-forum.com/u/Justin_Caldwell)\
**Post date:** [September 9, 2006, 1:33am UTC](https://www.ruby-forum.com/t/render-rjs-and-action-from-submit-tag/67940/4 "2006-09-09T01:33:22Z")

</div>

On 08 Sep 2006, at 22:54, Justin Caldwell wrote:

> “:multipart =\> true” and ajax can’t handle files/images.
> 
> Played around with a hidden iframe, but can’t get around having to  
> render twice.
> 
> So I’m still stumped.

Have a look at the plugin here: [http://sean.treadway.info/svn/](http://sean.treadway.info/svn/)  
plugins/responds\_to\_parent/README  
It lets your use respond\_to\_parent and an rjs block to get your rjs  
to eval in the parent window. This uses the hidden iframe solution  
and it works well from what i’ve heard.

Best regards

Peter De Berdt
