Forum: Ruby on Rails nested ajax functionality in a span element inside div_for

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
5e61b7c3b9e688807b29e7b8b0bb9f84?d=identicon&s=25 RubyRed (Guest)
on 2009-05-10 21:33
(Received via mailing list)
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 %>
  <h2><span id="vote_score"> <%= story.votes.size %></span>
 <span id="vote_link" >
   <%= 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 %> </h2>
  <%= simple_format h(story.body) %>
  </span>

  <% end %>
--------------------------------


vote.rjs
------------------------------------------------------------------------------
page.replace_html 'vote_score', "#{@post.votes.size}"
page[:vote_score].visual_effect :highlight
54404bcac0f45bf1c8e8b827cd9bb709?d=identicon&s=25 7stud -- (7stud)
on 2009-05-10 22:34
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 %>
>   <h2><span id="vote_score"> <%= story.votes.size %></span>
>  <span id="vote_link" >
>    <%= 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 %> </h2>
>   <%= simple_format h(story.body) %>
>   </span>
>
>   <% 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 topic is locked and can not be replied to.