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</a>

<div id=review style="display: none">

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

</div>

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:

<div id="review_for<%= restaurant.id %>" style="display: none">

<a href="#" onClick="toggleReviews('review_for<%= restaurant.id %>', ...)";>See Reviews</a>

-- Long http://FATdrive.tv/wall/trakb/10-Long http://FATdrive.tv/ - store, play, share

Long wrote:

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

<div id="review_for<%= restaurant.id %>" style="display: none">

<a href="#" onClick="toggleReviews('review_for<%= restaurant.id %>', ...)";>See Reviews</a>

-- Long http://FATdrive.tv/wall/trakb/10-Long http://FATdrive.tv/ - store, play, share

From: "Steve Glaz" <rails-mailing-list@andreas-s.net> To: <rubyonrails-talk@googlegroups.com> 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

<%= link_to_function "See Reviews",                       "Element.toggle('review_for#{restaurant.id}')" %>

-Rob

Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com

Rob Biedenharn 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