# RoR 1.1 RJS problem

**URL:** <https://www.ruby-forum.com/t/ror-1-1-rjs-problem/56479>\
**Category:** Rails\
**Created:** [March 31, 2006, 4:39pm UTC](https://www.ruby-forum.com/t/ror-1-1-rjs-problem/56479 "2006-03-31T16:39:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gander](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/da6949/32.png) [@gander](https://www.ruby-forum.com/u/gander)\
**Post date:** [March 31, 2006, 4:39pm UTC](https://www.ruby-forum.com/t/ror-1-1-rjs-problem/56479/1 "2006-03-31T16:39:42Z")

</div>

I’ve been playing with the new RJS stuff in RoR1.1, and I have to say  
that I’m am extremely impressed, NICE! work guys. However, I seem to be  
having a bit of a problem. I promise, I’ve googled the hell out of it  
and haven’t found an answer.

Set up: Putting together a little proof of concept app. Display a form  
(index.rhtml) that just has a button to call the next action  
(show\_admin\_conf). Have created a show\_admin\_conf.rjs and the  
show\_admin\_conf method is actually empty. When it goes to the  
show\_admin\_conf.rjs I’m just asking it to hide a

- tag with a given  
id. What I get is the 
- tag updated AND the result of the RJS in the  
content area where I’m trying to update (not related to 
- tag) Should  
be pulling up a new partial in show\_admin\_conf.rhtml.

the controller code

class AbeProto1Controller \< ApplicationController

def index  
end

def show\_conf\_admin  
end

def conf\_admin  
render( :partial =\> “conf\_net”)  
end  
end

* * *

The index.rhtml:

\<%=  
javascript\_tag(“document.getElementById(‘index’).className=‘selected’;”)  
%\>

 \<%= $PROJECT\_NAME %\> Configuration Wizard

 This wizard will walk you through configuring your \<%= $PROJECT\_NAME %\> system. Click the Begin button to start the process.

\<%= form\_remote\_tag(:url =\> { :action =\> “show\_conf\_admin” }, :update =\>  
“main”) %\>

```
    <div id="main_content">
     -no content-
    </div> <!-- main_content -->

    <div id="main_options">
            Press Begin to start.

            <div id="main_buttons">
                    <%= submit_tag("Begin!") %>
            </div> <!-- main_buttons -->

    </div> <!-- main_options -->

```

\<%= end\_form\_tag %\>

* * *

the show\_admin\_conf.rjs (in same directory as my rhtml files)

page[‘index’].hide  
puts “ONE”  
render(:partial =\> ‘conf\_admin’, :update =\> ‘main’)  
puts “TWO”

* * *

And, finally, the \_conf\_admin.rhtml partial:

\<%=  
javascript\_tag(“document.getElementById(‘conf\_admin’).className=‘selected’;”)  
%\>

 \<%= $PROJECT\_NAME %\>: Configure Administrator

 Complete the following form to configure your administrative user. This user will have access to all portions of the system. Please choose a strong password and provide an email address that is monitored by an administrator.

\<%= form\_remote\_tag(:url =\> { :action =\> “conf\_admin” },

```
                                    :update => "main") %>

    <div id="main_content">
     -no content-
    </div> <!-- main_content -->

    <div id="main_options">
            Press Next to continue.

            <div id="main_buttons">
                    <%= submit_tag("Next") %>
            </div> <!-- main_buttons -->

    </div> <!-- main_options -->

```

\<%= end\_form\_tag %\>

* * *

The div id “main” defined in my template (not really interesting, so not  
included) is where the index.rhtml and \_conf\_admin.rhtml are supposed to  
render.

Ok, now, here’s what I’m getting, and ALL I’m getting in my “main” div:

$(“index”).hide();

Which is correct. . .sort of. It DOES hide the index object correctly,  
but displays the above in the div and does not show my partical in the  
“main” div.

Been working on this for about 24 hours, most of that spent googling and  
reading over everybody’s examples (again, and again, and again : b).

Any help would be GREATLY appreciated. I know something silly is going  
on here, but for the life of me I can’t figure out what.

Thanks!

Gerald

---

<div class="post-metadata">

**Author:** ![gander](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/da6949/32.png) [@gander](https://www.ruby-forum.com/u/gander)\
**Post date:** [March 31, 2006, 4:44pm UTC](https://www.ruby-forum.com/t/ror-1-1-rjs-problem/56479/2 "2006-03-31T16:44:03Z")

</div>

Umm, I should note: I am a Ruby/RoR newbie, have just finished the  
pragmatic agile development with rails book (with the pickaxe handy for  
reference) and am just trying to put that stuff into practice. If you  
guys see something that I’m screwing up that’s not related, or something  
that’s not “idiomatic” I will gratefully take any advice.

G

---

<div class="post-metadata">

**Author:** ![gander](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/da6949/32.png) [@gander](https://www.ruby-forum.com/u/gander)\
**Post date:** [March 31, 2006, 4:50pm UTC](https://www.ruby-forum.com/t/ror-1-1-rjs-problem/56479/3 "2006-03-31T16:50:57Z")

</div>

> \<%= form\_remote\_tag(:url =\> { :action =\> “show\_conf\_admin” }, :update =\>  
> “main”) %\>

Remove :update =\> “main”, use RJS to update whatever bits you want.

> page[‘index’].hide  
> puts “ONE”  
> render(:partial =\> ‘conf\_admin’, :update =\> ‘main’)  
> puts “TWO”

To replace the contents of the div ‘main’ with the conf\_admin partial,  
use:

page.replace\_html ‘main’, :partial =\> ‘conf\_admin’

You can also use Element.addClassName (from Prototype) to add that class  
name:

page[‘conf\_admin’].add\_class\_name(‘selected’) # Should work, never  
used  
it though…

Your example seems a bit convoluted, it could be cleaned up a lot.

-Jonathan.

---

<div class="post-metadata">

**Author:** ![gander](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/da6949/32.png) [@gander](https://www.ruby-forum.com/u/gander)\
**Post date:** [March 31, 2006, 4:57pm UTC](https://www.ruby-forum.com/t/ror-1-1-rjs-problem/56479/4 "2006-03-31T16:57:02Z")

</div>

On Fri, Mar 31, 2006 at 04:39:43PM +0200, Gerald A. wrote:

> * * *
> 
> the show\_admin\_conf.rjs (in same directory as my rhtml files)
> 
> page[‘index’].hide  
> puts “ONE”  
> render(:partial =\> ‘conf\_admin’, :update =\> ‘main’)  
> puts “TWO”
> 
> * * *

At least one of your problems is that you aren’t meant to use render  
from an  
rjs template. Instead you’ll use, for example, replace\_html on the page  
object.

For example:

page.replace\_html ‘main’, :partial =\> ‘conf\_admin’

marcel

---

<div class="post-metadata">

**Author:** ![gander](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/da6949/32.png) [@gander](https://www.ruby-forum.com/u/gander)\
**Post date:** [March 31, 2006, 5:22pm UTC](https://www.ruby-forum.com/t/ror-1-1-rjs-problem/56479/5 "2006-03-31T17:22:47Z")

</div>

> page[‘index’].hide line was a test, the actual goal is to set the class  
> of the
> 
> - blah to be ‘complete’. I’m

grr, sorry, typo. . .

---

<div class="post-metadata">

**Author:** ![gander](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/da6949/32.png) [@gander](https://www.ruby-forum.com/u/gander)\
**Post date:** [March 31, 2006, 5:21pm UTC](https://www.ruby-forum.com/t/ror-1-1-rjs-problem/56479/6 "2006-03-31T17:21:58Z")

</div>

That was it guys, thank you very much! It never even crossed my mind to  
revisit the :update in my form action (it was originally done as a  
non-rjs test). I had played with page.replace\_html in an earlier  
iteration, but with the rjs and :update set up as it was, it didn’t work  
exactly right ; )

Jonathan: Like I said above, I’m learning. If you have any specific  
criticism I’m interested in hearing it. I know that the example is  
contrived, but don’t understand where it’s convoluted.

Finally, there’s one more little related problem. The  
page[‘index’].hide line was a test, the actual goal is to set the class  
of the

- blah to be ‘complete’. I’m  
trying to use page[‘index’].assign(‘class’,‘complete’) but that’s not  
working. Am I on the right path there?

Thanks again guys, really blown away with the rapid reponse ; )
