How to vote using Rails 3 gem 'thumbs_up'?

So, I want voices to be launched using jQuery / AJAX and image. that is, I have an icon and thumbs down.

I installed the gem and ran rake db: migrate and took it apart.

But I'm not sure how to vote in my application.

In my model, I use one model for acts_as_voter, which is my model Client. The model that acts_as_votableis my model Upload. Thus, the client votes for the download. This is literally a big thumbs_up, not so much a โ€œvoiceโ€ as such, because there is no karma or anything else. These are just thumbs up / down from each client per download.

In my opinion, thatโ€™s how I would like to vote:

$("div#upvote img").live("click", compv.comments.upvote);

How can I use this to actually implement an action upvoteusing this Rails 3 stone?

Edit: If you are interested in knowing what the function does compv.comments.upvotein the current form, you can see it here:

    compv.comments.upvote = function(event){
    var uploaderID = compv.comments.getUploadID(event.target);
    $.ajax({
        url: '/uploads/'+uploaderID+'/upvote.js',
        success: function(data, status, xhr){
            var uploadElement = $("li[data-upload-id="+uploaderID+"]");
            uploadElement.attr('data-upload-upvote', parseInt(uploadElement.attr('data-upload-upvote'))+1);
            var imgElement = uploadElement.find("div.image-wrapper > img");
            var img_opacity = imgElement.css('opacity');
            if(img_opacity < 1 ) {  
                imgElement.fadeTo(600, 1, function() {
            }); 
            }
            imgElement.removeClass("downvoted");
            imgElement.addClass("upvoted");
        }
    });
};

However, I know well that this is likely to change if I want this gem to work correctly. It was only my version, trying to do what this gemstone can do (although, I would prefer an implementation out of this gem).

+3
source share
1 answer

This is more a question of how to create Ajax actions in Rails in general than anything in this particular stone.

: , "thumbs_up" Rails 3

jQuery - :

$.post('/posts/' + id + '/vote_up', function() {
  alert('success');
})
.error(function() { alert('Vote error.'); });

, .

+3

Source: https://habr.com/ru/post/1795162/


All Articles