Guest User

Untitled

a guest
Jan 20th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. class ResultsController < ApplicationController
  2.  
  3. def index
  4. @question = Question.find(params[:id])
  5.  
  6. @options = Option.where(:question_id => params[:id])
  7.  
  8. @total = Vote.where(:question_id => params[:id]).count
  9.  
  10. if @total == 0
  11. redirect_to options_path(@question)
  12. else
  13.  
  14. @av = 100/@total
  15.  
  16. @optionsgraph = ""
  17. @votesgraph = ""
  18.  
  19. @options.each do |option|
  20. @optionsgraph = "#{@optionsgraph}|#{option.option[0..10]}..."
  21. @votesgraph = "#{@votesgraph},#{option.votes.count}"
  22. end
  23.  
  24. @optionsgraph = @optionsgraph[1..-1]
  25. @votesgraph = @votesgraph[1..-1]
  26.  
  27. end
  28.  
  29. @title = @question.question + "?" # add
  30. end
  31.  
  32. end
Add Comment
Please, Sign In to add comment