# Not quite sure how to do this?

**URL:** <https://www.ruby-forum.com/t/not-quite-sure-how-to-do-this/92510>\
**Category:** Rails\
**Created:** [April 20, 2007, 4:55am UTC](https://www.ruby-forum.com/t/not-quite-sure-how-to-do-this/92510 "2007-04-20T04:55:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 20, 2007, 4:55am UTC](https://www.ruby-forum.com/t/not-quite-sure-how-to-do-this/92510/1 "2007-04-20T04:55:27Z")

</div>

Everyone’s has to seen this but don’t know what it is called nor where  
to start. Take youtube for example, in their comments or tags section  
there is a (more) or (less) link that expands and collapses. Is this  
AJAX? How would you go about doing this is in Ruby?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 20, 2007, 7:21am UTC](https://www.ruby-forum.com/t/not-quite-sure-how-to-do-this/92510/2 "2007-04-20T07:21:38Z")

</div>

It’s JavaScript (probably) and there are various ways to do it - I’d  
recomend checking out the Prototype library which makes this kind of  
thing easer. Using Prototype you might do something like

this is some text
showhide

Clicking the links will hide and show the ‘thisPanel’ div. Expanding  
and contracting is similarly achieved but really depends on the type  
of effect you want.

Dale

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 21, 2007, 7:22am UTC](https://www.ruby-forum.com/t/not-quite-sure-how-to-do-this/92510/3 "2007-04-21T07:22:35Z")

</div>

here’s another way that’s a bit more railsish:

 \<%= description.truncate(100) %\> \<%= link\_to\_function "(more)", f = update\_page { |p| p.toggle("description"); p.toggle("description\_more") } %\>

 \<%= description %\> \<%= link\_to\_function "(less)", f %\>

This really isn’t AJAX. It would be, if the “more” description was  
being pulled from the server on click.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 24, 2007, 12:15am UTC](https://www.ruby-forum.com/t/not-quite-sure-how-to-do-this/92510/4 "2007-04-24T00:15:48Z")

</div>

So the function sits on the top of the view? I never really worked with  
Javascripts also. This is all new to me. Also, I was messing around,  
not sure, but I have multiple items from a search that I do. But I was  
limited to one item only to be able to toggle. I tried putting the  
entire item in a div, but couldn’t. Here is what I’m using:

Show Items

That is what I’m doing. I have to use intCount because I have multiple  
categories, and under each category are items. So, I want to display  
the category, but hide the items and use the more or less. Could you  
please elaborate if it is possible to do this?

Eden Li wrote:

> here’s another way that’s a bit more railsish:
> 
> \<%= description.truncate(100) %\> \<%= link\_to\_function "(more)", f = update\_page { |p| p.toggle("description"); p.toggle("description\_more") } %\>
> 
> \<%= description %\> \<%= link\_to\_function "(less)", f %\>
> 
> This really isn’t AJAX. It would be, if the “more” description was  
> being pulled from the server on click.
