Nested ajax functionality in a span element inside div_for

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

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs