Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def vote
- @post = Post.find(params[:post_id])
- temprating = @post.rating * @post.rating_count
- @post.rating_count = @post.rating_count + 1
- temprating = temprating + params[:rating].to_i
- temprating = temprating / @post.rating_count
- @post.rating = temprating.to_i
- respond_to do |format|
- if @post.save
- format.html { redirect_to @post, notice: 'Rating updated.' }
- format.json { render json: @post.rating }
- else
- format.html { redirect_to @post, notice: 'Rating failed.' }
- format.json { render json: @post.errors }
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment