# Simple Problem

**URL:** <https://www.ruby-forum.com/t/simple-problem/131987>\
**Category:** Rails\
**Created:** [March 14, 2008, 9:40pm UTC](https://www.ruby-forum.com/t/simple-problem/131987 "2008-03-14T21:40:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sjglazer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ee59a6/32.png) [@sjglazer](https://www.ruby-forum.com/u/sjglazer)\
**Post date:** [March 14, 2008, 9:40pm UTC](https://www.ruby-forum.com/t/simple-problem/131987/1 "2008-03-14T21:40:37Z")

</div>

Hello there,

I have what I think is a simple problem that I was hoping someone could  
help me with. I have an application that keeps track of many  
restaurants. Each restaurant has many user reviews associated with it.  
When a user does a search it will return a list of restaurants. I would  
like to have a “see reviews” link with each restaurant listing.

Now when someone clicks on the “see reviews” link I would like to have  
the reviews appear instantly below the restaurant listing without a page  
refresh.

Now the way I am doing it is by pre-loading and hiding the reviews. My  
partial for displaying each restaurant looks like this:

\<a href="#" onClick=“toggleReviews()”;\>See Reviews

\<% if !listing.reviews.blank? %\>  
\<%= render :partial =\> ‘review’, :collection =\> listing.reviews %\>  
\<% end %\>

Now the problem is in my toggleReviews function I need the div id of  
the element to toggle. If I use “review” it will show the reviews for  
all restaurants. Any ideas how I can dynamically set the div id to  
something like:

“review” + listing.review.id so that I can toogle the correct one? Or is  
there a better way to accomplish what I am trying to do.

Thanks,  
steve

---

<div class="post-metadata">

**Author:** ![sjglazer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ee59a6/32.png) [@sjglazer](https://www.ruby-forum.com/u/sjglazer)\
**Post date:** [March 14, 2008, 9:54pm UTC](https://www.ruby-forum.com/t/simple-problem/131987/2 "2008-03-14T21:54:01Z")

</div>

Assuming each restaurant has a unique ID, I would do the following:

\<a href=“#” onClick=“toggleReviews(‘review\_for\<%= restaurant.id %\>’,  
…)”;\>See Reviews

– Long  
[http://FATdrive.tv/wall/trakb/10-Long](http://FATdrive.tv/wall/trakb/10-Long)  
[http://FATdrive.tv/](http://FATdrive.tv/) - store, play, share

----- Original Message -----  
From: “Steve G.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Sent: Friday, March 14, 2008 3:40 PM  
Subject: [Rails] Simple Problem

---

<div class="post-metadata">

**Author:** ![sjglazer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ee59a6/32.png) [@sjglazer](https://www.ruby-forum.com/u/sjglazer)\
**Post date:** [March 14, 2008, 10:12pm UTC](https://www.ruby-forum.com/t/simple-problem/131987/3 "2008-03-14T22:12:11Z")

</div>

Long wrote:

> Assuming each restaurant has a unique ID, I would do the following:
> 
> \<a href=“#” onClick=“toggleReviews(‘review\_for\<%= restaurant.id %\>’,  
> …)”;\>See Reviews
> 
> – Long  
> [http://FATdrive.tv/wall/trakb/10-Long](http://FATdrive.tv/wall/trakb/10-Long)  
> [http://FATdrive.tv/](http://FATdrive.tv/) - store, play, share
> 
> ----- Original Message -----  
> From: “Steve G.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> To: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> Sent: Friday, March 14, 2008 3:40 PM  
> Subject: [Rails] Simple Problem

Thanks for the help - I think were on the right track. I was actually  
trying to use the following:

\<%= link\_to\_function “See Reviews”, “Element.toggle(‘review\_for’)” %\>

but don’t know how to get the restaurant ID in the toggle name. I tried  
this

\<%= link\_to\_function “See Reviews”, “Element.toggle(‘review\_for’ +  
restaurant.id)” %\>

and it didn’t work. Any suggestions?

thanks again,  
steve

---

<div class="post-metadata">

**Author:** ![sjglazer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ee59a6/32.png) [@sjglazer](https://www.ruby-forum.com/u/sjglazer)\
**Post date:** [March 14, 2008, 11:34pm UTC](https://www.ruby-forum.com/t/simple-problem/131987/4 "2008-03-14T23:34:38Z")

</div>

On Mar 14, 2008, at 5:12 PM, Steve G. wrote:

> > [http://FATdrive.tv/](http://FATdrive.tv/) - store, play, share
> 
> thanks again,  
> steve

\<%= link\_to\_function “See Reviews”,  
“Element.toggle(‘review\_for#{restaurant.id}’)” %\>

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![sjglazer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ee59a6/32.png) [@sjglazer](https://www.ruby-forum.com/u/sjglazer)\
**Post date:** [March 15, 2008, 5:17am UTC](https://www.ruby-forum.com/t/simple-problem/131987/5 "2008-03-15T05:17:34Z")

</div>

Rob B. wrote:

> \<%= link\_to\_function “See Reviews”,  
> “Element.toggle(‘review\_for#{restaurant.id}’)” %\>

Good suggestion Rob! That should work if the DIV id is set accordingly.

Long
