# Nested ajax functionality in a span element inside div\_for

**URL:** <https://www.ruby-forum.com/t/nested-ajax-functionality-in-a-span-element-inside-div-for/167643>\
**Category:** Rails\
**Created:** [May 10, 2009, 9:33pm UTC](https://www.ruby-forum.com/t/nested-ajax-functionality-in-a-span-element-inside-div-for/167643 "2009-05-10T21:33:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![RubyRed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3bc359/32.png) [@RubyRed](https://www.ruby-forum.com/u/RubyRed)\
**Post date:** [May 10, 2009, 9:33pm UTC](https://www.ruby-forum.com/t/nested-ajax-functionality-in-a-span-element-inside-div-for/167643/1 "2009-05-10T21:33:01Z")

</div>

Hi,  
I am having the following scenario to . In a page I have a list of  
stories, I would like to add the voting fuctionality (digg style) for  
each stories. I need the voting score to be displayed simultaniously  
(using AJAX). I am using the following listed code snippet for this  
but, I have a minor problem, since I am updating the \<span  
id=“vote\_score” …\> using the vote.rjs. It always updates the score of  
first story only. Does anyone has any solution for this. Thanks in  
advance

## \_story.html.erb

\<% div\_for story do %\>

## \<%= story.votes.size %\> \<%= link\_to\_remote 'Vote Up', {:url =\> {:action =\> 'vote', :id =\> post.id}}, {:href =\> url\_for(:action =\> 'vote', :id =\> story.id)}%\> \<%= link\_to\_unless\_current h(post.title), story %\>
 \<%= simple\_format h(story.body) %\> 
## \<% end %\>

## vote.rjs

page.replace\_html ‘vote\_score’, “#{@post.votes.size}”  
page[:vote\_score].visual\_effect :highlight

---

<div class="post-metadata">

**Author:** ![RubyRed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/3bc359/32.png) [@RubyRed](https://www.ruby-forum.com/u/RubyRed)\
**Post date:** [May 10, 2009, 10:34pm UTC](https://www.ruby-forum.com/t/nested-ajax-functionality-in-a-span-element-inside-div-for/167643/2 "2009-05-10T22:34:53Z")

</div>

RubyRed wrote:

> Hi,  
> I am having the following scenario to . In a page I have a list of  
> stories, I would like to add the voting fuctionality (digg style) for  
> each stories. I need the voting score to be displayed simultaniously  
> (using AJAX). I am using the following listed code snippet for this  
> but, I have a minor problem, since I am updating the \<span  
> id=“vote\_score” …\> using the vote.rjs. It always updates the score of  
> first story only. Does anyone has any solution for this. Thanks in  
> advance
> 
> ## \_story.html.erb
> 
> \<% div\_for story do %\>
> 
> ## \<%= story.votes.size %\> \<%= link\_to\_remote 'Vote Up', {:url =\> {:action =\> 'vote', :id =\> post.id}}, {:href =\> url\_for(:action =\> 'vote', :id =\> story.id)}%\> \<%= link\_to\_unless\_current h(post.title), story %\>
> \<%= simple\_format h(story.body) %\> 
> ## \<% end %\>
> 
> ## vote.rjs
> 
> page.replace\_html ‘vote\_score’, “#{@post.votes.size}”  
> page[:vote\_score].visual\_effect :highlight

How about:

page.replace\_html ‘vote\_score’, “#{@post.votes.size}”  
page.replace\_html ‘another id’, “something else”

which might lend itself to some sort of loop.
