I created a house scaffold which has many reviews and the reviews can be
voted on. All the reviews for a house are shown on the house show page.
Then each review has a vote button and a display to show the current
number of votes. I would like the vote button to vanish and the vote
count to change by AJAX after each vote.

# reviews/_rev.html.erb
<% @house.reviews.each do |review| %>
posted <%= time_ago_in_words review.created_at %> ago by <%=
review.user.username %> |
<p id='votes'><%= pluralize(review.votes_count, 'vote') %></p>

<% if current_user %>
<%= form_for(@vote, :remote => true) do |f| %>
<%= f.hidden_field "review_id", :value => review.id %>
<%= f.hidden_field "user_id", :value => current_user.id %>

<%= f.submit "vote" %>

#votes controller
def create

r = params[:vote][:review_id]
@review = Review.find(r)
@vote = @review.votes.build(params[:vote])
@vote.user_id = current_user.id

respond_to do |format|
if @vote.save

format.js { }



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

As it stands now, the vote will be posted but the AJAX will not work.
It will say undefined variable 'review'.

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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 6 | next ›
Discussion Overview
grouprubyonrails-talk @
postedOct 14, '11 at 12:31a
activeOct 16, '11 at 2:27a

2 users in discussion

Sean Six: 4 posts Tim Shaffer: 2 posts



site design / logo © 2022 Grokbase