views:

53

answers:

1

I have a loop in my view that renders many partials: each partial is a simple toggle to perform a save/unsave operation on a record. Each partial toggles the boolean field using javascript then updates itself, and the controller finishes by saying:

$ controller
render :partial => "save_unsave_buttons", :locals => {:matching => @matching}, :layout => false

# view    
<div id=<%= "save#{match.id}" -%>>
<%= render :partial => "save_unsave_buttons", :locals => {:matching => match} %>
</div>

When the controller renders the save_unsave_buttons partial, it isn't rendering to the right div; it just updates the partial for the first record it finds. How can I ask the controller to render the save_unsave_buttons partial to the div with the right id?

Thanks!

A: 

Looking at only the little info that you provided for your problem i guess the culprit in the code is the div tag.

The div tag should be within the partial.

EDIT: What your code does is it creates a single div with id save(the first match.id) and renders the partial within it. If I understood you correctly you need a div for each match. For that the div itself should be within the partial.

So pass the match.id to the partial in a collection. Your view should be:

# view    

<%= render :partial => "save_unsave_buttons", :locals => {:matching => match, :collection => {@match_id => match.id} } %>

and in your partial _sav_unsave_buttons.html.erb:

<% content_tag :div, id => "save#{@match_id}" do %>

     #YOUR CODE GOES HERE!

<% end -%>
Shripad K