Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def vote_up
- @question = get_question params[:id]
- if current_user != @question.user
- render :json => @question.vote(current_user, 'up').to_json
- end
- end
- def vote_down
- @question = get_question params[:id]
- if current_user != @question.user
- render :json => @question.vote(current_user, 'down').to_json
- end
- end
- def vote(user, vote)
- if user.voted?(self)
- 'Question already voted'
- else
- I18n.t('question.voted') if user.send("#{vote}_vote", self)
- end
- end
- <script>
- $('#question_vote_up').live('ajax:success', function(evt, data, status, xhr) {
- $('#question_vote_up').remove()
- $('#question_vote_down').remove()
- alert(xhr.responseText)
- })
- $('#question_vote_down').live('ajax:success', function(evt, data, status, xhr) {
- $('#question_vote_up').remove()
- $('#question_vote_down').remove()
- alert(xhr.responseText)
- })
- </script>
- <% if current_user != @question.user %>
- <%= link_to t('question.vote_up'), { :action => "vote_up" }, :id => "question_vote_up", :remote => true %>
- <%= link_to t('question.vote_down'), { :action => "vote_down" }, :id => "question_vote_down", :remote => true %>
- <% end %>
- if current_user != @question.user
- def getQuestion(direction)
- @question = get_question params[:id]
- if current_user != @question.user
- render :json => @question.vote(current_user, direction).to_json
- else
- render :nothing => true
- end
- end
- def vote_up
- getQuestion "up"
- end
- def vote_down
- getQuestion "down"
- end
Add Comment
Please, Sign In to add comment