# Not getting the whole RJS-based partial rendering concept

**URL:** <https://www.ruby-forum.com/t/not-getting-the-whole-rjs-based-partial-rendering-concept/93559>\
**Category:** Rails\
**Created:** [April 4, 2006, 8:06pm UTC](https://www.ruby-forum.com/t/not-getting-the-whole-rjs-based-partial-rendering-concept/93559 "2006-04-04T20:06:14Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![aginghipster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e9c0ed/32.png) [@aginghipster](https://www.ruby-forum.com/u/aginghipster)\
**Post date:** [April 4, 2006, 8:06pm UTC](https://www.ruby-forum.com/t/not-getting-the-whole-rjs-based-partial-rendering-concept/93559/1 "2006-04-04T20:06:14Z")

</div>

I have been trying all kinds of different ways to produce what I think  
should be a simple effect, but have not had any luck yet and apparently  
I am not following the general idea…

What I am trying to accomplish is the following (part 1 works and part 2  
does not):

1. One of my views has a link\_to\_remote which updates a div container  
with a table of data

my example is

\<%= link\_to\_remote( "(display stuff)", :update =\> "div\_for\_stuff", :url =\> "/stuff/do\_stuff" ) %\>

This works, the page adjusts and the table appears in div\_for\_stuff

1. At the point where the table appears I would like for the above link  
to be replaced with a link to clear the table.

I have tried all manner of aproaches for this and just don’t get it, I  
have the link\_to in its own div container and have tried using a  
page.replace\_html but the div container does not change.

eg  
\<%  
render :update do |page|  
page.replace\_html ‘linkdiv’, :partial =\> “do\_clear”  
end  
%\>

in \_do\_clear.rhtml I have a new link\_to which never appears.

I’m confused, can anyone take pity on me and point me to some actual  
working code that might do this sort of thing?

Thanks in advance for any help you can provide  
-Andy

---

<div class="post-metadata">

**Author:** ![aginghipster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e9c0ed/32.png) [@aginghipster](https://www.ruby-forum.com/u/aginghipster)\
**Post date:** [April 4, 2006, 8:24pm UTC](https://www.ruby-forum.com/t/not-getting-the-whole-rjs-based-partial-rendering-concept/93559/2 "2006-04-04T20:24:35Z")

</div>

Andrew

```
> 2. At the point where the table appears I would like for the above

```

link  
\> to be replaced with a link to clear the table.

I would rather  
1/ place the 2 links in the original html,  
2/ hide the 2nd link (clear\_the\_table) with  
style=“display:none”  
and then  
3/ hide the first link, and show the 2nd - clear\_the\_table - link.

When applicable, I find this way simpler to code, understand and debug.

Alain

---

<div class="post-metadata">

**Author:** ![aginghipster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e9c0ed/32.png) [@aginghipster](https://www.ruby-forum.com/u/aginghipster)\
**Post date:** [April 4, 2006, 9:04pm UTC](https://www.ruby-forum.com/t/not-getting-the-whole-rjs-based-partial-rendering-concept/93559/3 "2006-04-04T21:04:12Z")

</div>

Thank you Alain, I am not at all opposed to hiding one link and  
displaying the other ( I assume you mean having a div container for each  
and setting the appropriate style )

Unfortunately, the problem remains for me that I still do not know how  
to modify those style attributes from the action that gets called via  
the first link, I still have not had any success doing a  
page.replace\_html, or know if that is even the right approach.

Thanks!  
-Andy

Alain R. wrote:

> Andrew
> 
> ```
> > 2. At the point where the table appears I would like for the above
> 
> ```
> 
> link  
> \> to be replaced with a link to clear the table.
> 
> I would rather  
> 1/ place the 2 links in the original html,  
> 2/ hide the 2nd link (clear\_the\_table) with  
> style=“display:none”  
> and then  
> 3/ hide the first link, and show the 2nd - clear\_the\_table - link.
> 
> When applicable, I find this way simpler to code, understand and debug.
> 
> Alain

---

<div class="post-metadata">

**Author:** ![aginghipster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e9c0ed/32.png) [@aginghipster](https://www.ruby-forum.com/u/aginghipster)\
**Post date:** [April 4, 2006, 9:30pm UTC](https://www.ruby-forum.com/t/not-getting-the-whole-rjs-based-partial-rendering-concept/93559/4 "2006-04-04T21:30:43Z")

</div>

Andrew C. wrote:

> I have been trying all kinds of different ways to produce what I think  
> should be a simple effect, but have not had any luck yet and apparently  
> I am not following the general idea…
> 
> What I am trying to accomplish is the following (part 1 works and part 2  
> does not):
> 
> 1. One of my views has a link\_to\_remote which updates a div container  
> with a table of data
> 
> my example is
> 
> \<%= link\_to\_remote( "(display stuff)", :update =\> "div\_for\_stuff", :url =\> "/stuff/do\_stuff" ) %\>
> 
> This works, the page adjusts and the table appears in div\_for\_stuff
> 
> 1. At the point where the table appears I would like for the above link  
> to be replaced with a link to clear the table.
> 
> I have tried all manner of aproaches for this and just don’t get it, I  
> have the link\_to in its own div container and have tried using a  
> page.replace\_html but the div container does not change.
> 
> eg  
> \<%  
> render :update do |page|  
> page.replace\_html ‘linkdiv’, :partial =\> “do\_clear”  
> end  
> %\>
> 
> in \_do\_clear.rhtml I have a new link\_to which never appears.
> 
> I’m confused, can anyone take pity on me and point me to some actual  
> working code that might do this sort of thing?
> 
> Thanks in advance for any help you can provide  
> -Andy

Did something quite similar a moment ago, I think something like this  
should work:

 \<%= link\_to\_remote "Load tables", :url =\>{ :action =\> :add\_stuff }, :loading =\> "Element.update('header','Loading...')", :success =\> "Element.update('header','Stuff loaded')", :after =\> "Element.hide('add\_linkdiv'); Element.show('clear\_linkdiv'" %\>

 \<%= link\_to\_remote "Clear tables", :url =\>{ :action =\> :remove\_stuff }, :after =\> "Element.hide('clear\_linkdiv'); Element.show('add\_linkdiv'" %\>

---

<div class="post-metadata">

**Author:** ![aginghipster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e9c0ed/32.png) [@aginghipster](https://www.ruby-forum.com/u/aginghipster)\
**Post date:** [April 4, 2006, 10:02pm UTC](https://www.ruby-forum.com/t/not-getting-the-whole-rjs-based-partial-rendering-concept/93559/5 "2006-04-04T22:02:40Z")

</div>

\<%= link\_to\_remote( “(display)”,  
:url =\> { :action =\> “inline\_list”, :id =\> entry.id  
}  
%\>  
loose the :update (doesn’t work in RJS)

rjs file bij default ‘inline\_list.rjs’

in youre method you have the instance vars of course

then build youre rjs file

page.hide ‘old\_div’  
page.replace\_html ‘other\_div’, :partial =\> ‘whatever’  
page.visual\_effect :appear, ‘other\_div’

or use it in the method in the controller

render :update do |page|  
page.hide ‘old\_div’  
page.replace\_html ‘other\_div’, :partial =\> ‘whatever’  
page.visual\_effect :appear, ‘other\_div’  
end

---

<div class="post-metadata">

**Author:** ![aginghipster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e9c0ed/32.png) [@aginghipster](https://www.ruby-forum.com/u/aginghipster)\
**Post date:** [April 4, 2006, 9:48pm UTC](https://www.ruby-forum.com/t/not-getting-the-whole-rjs-based-partial-rendering-concept/93559/6 "2006-04-04T21:48:25Z")

</div>

This would be great, however I am getting parse errors.

have this:

\<%= link\_to\_remote( “(display)”,  
:update =\> “div\_1”,  
:url =\> { :action =\> “inline\_list”, :id =\> entry.id  
},  
:after =\> Element.hide(‘linkdiv\_show’) %\>

The error is:

parse error, unexpected ‘;’, expecting ‘)’

I also tried putting double-quotes around the Element.hide() as in your  
example but I get the same error.

Any ideas?

Thanks,  
Andy

BobFunk wrote:

> Andrew C. wrote:
> 
> > I have been trying all kinds of different ways to produce what I think  
> > should be a simple effect, but have not had any luck yet and apparently  
> > I am not following the general idea…
> > 
> > What I am trying to accomplish is the following (part 1 works and part 2  
> > does not):
> > 
> > 1. One of my views has a link\_to\_remote which updates a div container  
> > with a table of data
> > 
> > my example is
> > 
> > \<%= link\_to\_remote( "(display stuff)", :update =\> "div\_for\_stuff", :url =\> "/stuff/do\_stuff" ) %\>
> > 
> > This works, the page adjusts and the table appears in div\_for\_stuff
> > 
> > 1. At the point where the table appears I would like for the above link  
> > to be replaced with a link to clear the table.
> > 
> > I have tried all manner of aproaches for this and just don’t get it, I  
> > have the link\_to in its own div container and have tried using a  
> > page.replace\_html but the div container does not change.
> > 
> > eg  
> > \<%  
> > render :update do |page|  
> > page.replace\_html ‘linkdiv’, :partial =\> “do\_clear”  
> > end  
> > %\>
> > 
> > in \_do\_clear.rhtml I have a new link\_to which never appears.
> > 
> > I’m confused, can anyone take pity on me and point me to some actual  
> > working code that might do this sort of thing?
> > 
> > Thanks in advance for any help you can provide  
> > -Andy
> 
> Did something quite similar a moment ago, I think something like this  
> should work:
> 
> \<%= link\_to\_remote "Load tables", :url =\>{ :action =\> :add\_stuff }, :loading =\> "Element.update('header','Loading...')", :success =\> "Element.update('header','Stuff loaded')", :after =\> "Element.hide('add\_linkdiv'); Element.show('clear\_linkdiv'" %\>
> 
> \<%= link\_to\_remote "Clear tables", :url =\>{ :action =\> :remove\_stuff }, :after =\> "Element.hide('clear\_linkdiv'); Element.show('add\_linkdiv'" %\>

---

<div class="post-metadata">

**Author:** ![aginghipster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e9c0ed/32.png) [@aginghipster](https://www.ruby-forum.com/u/aginghipster)\
**Post date:** [April 4, 2006, 11:55pm UTC](https://www.ruby-forum.com/t/not-getting-the-whole-rjs-based-partial-rendering-concept/93559/7 "2006-04-04T23:55:28Z")

</div>

Disregard that last message, if I had just tried a set of "s instead of  
's I’d have found the answer – thanks again for all your help!

-Andy

Andrew C. wrote:

> Excellent, this showed me a few things I was doing wrong and I am able  
> to get the display and hide links working now in a simplified fashion,  
> still have one small hurdle.
> 
> The div tag ids I am using are based on the id# for the data items, so I  
> have the following tags:
> 
> linkdiv\_1\_show  
> linkdiv\_1\_hide  
> commentsdiv\_1
> 
> eg where 1 is the id # for the specific item.
> 
> In the .rjs files I am trying to recreate the correct div tag ids but  
> its complaining, I’m sure I am missing the syntax since all of the  
> examples I have seen from the api/docs show static div ids.
> 
> eg
> 
> page[‘clinkdiv\_#{@eid}\_show’].hide
> 
> where @eid is defined in the controller, but I get this error:
> 
> TypeError: $(“clinkdiv\_#{@eid}\_show”) has no properties
> 
> Is there not a way to access that @eid from the .rjs file and use it in  
> a div id?
> 
> Thank you guys so much, I’m much closer to understanding all of this! 🙂  
> Andy

---

<div class="post-metadata">

**Author:** ![aginghipster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e9c0ed/32.png) [@aginghipster](https://www.ruby-forum.com/u/aginghipster)\
**Post date:** [April 4, 2006, 11:26pm UTC](https://www.ruby-forum.com/t/not-getting-the-whole-rjs-based-partial-rendering-concept/93559/8 "2006-04-04T23:26:42Z")

</div>

Excellent, this showed me a few things I was doing wrong and I am able  
to get the display and hide links working now in a simplified fashion,  
still have one small hurdle.

The div tag ids I am using are based on the id# for the data items, so I  
have the following tags:

linkdiv\_1\_show  
linkdiv\_1\_hide  
commentsdiv\_1

eg where 1 is the id # for the specific item.

In the .rjs files I am trying to recreate the correct div tag ids but  
its complaining, I’m sure I am missing the syntax since all of the  
examples I have seen from the api/docs show static div ids.

eg

page[‘clinkdiv\_#{@eid}\_show’].hide

where @eid is defined in the controller, but I get this error:

TypeError: $(“clinkdiv\_#{@eid}\_show”) has no properties

Is there not a way to access that @eid from the .rjs file and use it in  
a div id?

Thank you guys so much, I’m much closer to understanding all of this! 🙂  
Andy

Peter wrote:

> \<%= link\_to\_remote( “(display)”,  
> :url =\> { :action =\> “inline\_list”, :id =\> entry.id  
> }  
> %\>  
> loose the :update (doesn’t work in RJS)
> 
> rjs file bij default ‘inline\_list.rjs’
> 
> in youre method you have the instance vars of course
> 
> then build youre rjs file
> 
> page.hide ‘old\_div’  
> page.replace\_html ‘other\_div’, :partial =\> ‘whatever’  
> page.visual\_effect :appear, ‘other\_div’
> 
> or use it in the method in the controller
> 
> render :update do |page|  
> page.hide ‘old\_div’  
> page.replace\_html ‘other\_div’, :partial =\> ‘whatever’  
> page.visual\_effect :appear, ‘other\_div’  
> end
