[Rails] Re: AJAX vote update for a nested resource

2011-10-15 Thread Sean Six
Solution:

<% @house.reviews.each do |review| %>
$("#review_<%= review.id %>").html("<%= pluralize(review.votes_count, 
'vote') %>");
<% end %>

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: AJAX vote update for a nested resource

2011-10-14 Thread Sean Six
I'm not sure why it still isn't working for me.

<%= pluralize(review.votes_count, 'vote') 
%>


create.js.erb
$("review_<%= @review.id %>").html("<%= @review.votes_count %>")

I don't see any errors in the log.

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: AJAX vote update for a nested resource

2011-10-14 Thread Tim Shaffer
That's to be expected with your HTML.

What you currently have will generate HTML that looks like the following if 
you have 3 reviews:

1 vote
2 votes
3 votes

$("#votes").html("3 votes")
$("#votes").html("4 votes")
$("#votes").html("5 votes")

See the problem?

The problem is that each paragraph tag has the same ID. jQuery will only 
update the first one. Each paragraph needs to have a unique ID, then your 
JavaScript to update the paragraph needs to update the specific unique ID.

Including the primary key in the HTML ID is a good solution:



Then your jQuery can update the specific paragraph that it needs to:

$("#review_<%= review.id %>").html("<%= review.votes_count %>")


-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/8XDnjkoJ3SUJ.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: AJAX vote update for a nested resource

2011-10-14 Thread Sean Six
That doesn't quite work.  When I use <%= @review.votes_count %> in the 
create.js.erb file it updates the counter on the first review, 
regardless of whether the vote was placed on the first review or not.

I thought maybe if I loop through the reviews again the create.js.erb 
file it might work.

<% @house.reviews.each do |review| %>
$("#votes").html("<%= review.votes_count %>")
<% end %>

This did not work either.

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.



[Rails] Re: AJAX vote update for a nested resource

2011-10-14 Thread Tim Shaffer
You're defining @review as an instance variable, so you have to use it as 
one in the view:

$("#votes").html("<%= *@*review.votes_count %>")

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/Ocd3vOdvJUwJ.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.