Guest User

Untitled

a guest
Nov 24th, 2012
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 0.62 KB | None | 0 0
  1.  
  2.   def vote
  3.  
  4.     @post = Post.find(params[:post_id])
  5.     temprating = @post.rating * @post.rating_count
  6.     @post.rating_count = @post.rating_count + 1
  7.     temprating = temprating + params[:rating].to_i
  8.     temprating = temprating  / @post.rating_count
  9.     @post.rating =  temprating.to_i
  10.     respond_to do |format|
  11.       if @post.save
  12.         format.html { redirect_to @post, notice: 'Rating updated.' }
  13.         format.json { render json: @post.rating  }
  14.       else
  15.         format.html { redirect_to @post, notice: 'Rating failed.' }
  16.         format.json { render json: @post.errors }
  17.       end
  18.     end
  19.  
  20.  
  21.   end
Advertisement
Add Comment
Please, Sign In to add comment