Simple Problem

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

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/ - store, play, share

----- Original Message -----
From: “Steve G.” [email protected]
To: [email protected]
Sent: Friday, March 14, 2008 3:40 PM
Subject: [Rails] Simple Problem

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/ - store, play, share

----- Original Message -----
From: “Steve G.” [email protected]
To: [email protected]
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

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

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
[email protected]

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