Guest User

Untitled

a guest
Jul 15th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. def vote_up
  2. @question = get_question params[:id]
  3. if current_user != @question.user
  4. render :json => @question.vote(current_user, 'up').to_json
  5. end
  6. end
  7.  
  8. def vote_down
  9. @question = get_question params[:id]
  10. if current_user != @question.user
  11. render :json => @question.vote(current_user, 'down').to_json
  12. end
  13. end
  14.  
  15. def vote(user, vote)
  16. if user.voted?(self)
  17. 'Question already voted'
  18. else
  19. I18n.t('question.voted') if user.send("#{vote}_vote", self)
  20. end
  21. end
  22.  
  23. <script>
  24. $('#question_vote_up').live('ajax:success', function(evt, data, status, xhr) {
  25. $('#question_vote_up').remove()
  26. $('#question_vote_down').remove()
  27. alert(xhr.responseText)
  28. })
  29.  
  30. $('#question_vote_down').live('ajax:success', function(evt, data, status, xhr) {
  31. $('#question_vote_up').remove()
  32. $('#question_vote_down').remove()
  33. alert(xhr.responseText)
  34. })
  35. </script>
  36.  
  37. <% if current_user != @question.user %>
  38. <%= link_to t('question.vote_up'), { :action => "vote_up" }, :id => "question_vote_up", :remote => true %>
  39. <%= link_to t('question.vote_down'), { :action => "vote_down" }, :id => "question_vote_down", :remote => true %>
  40. <% end %>
  41.  
  42. if current_user != @question.user
  43.  
  44. def getQuestion(direction)
  45. @question = get_question params[:id]
  46. if current_user != @question.user
  47. render :json => @question.vote(current_user, direction).to_json
  48. else
  49. render :nothing => true
  50. end
  51. end
  52.  
  53. def vote_up
  54. getQuestion "up"
  55. end
  56.  
  57. def vote_down
  58. getQuestion "down"
  59. end
Add Comment
Please, Sign In to add comment