Question

I have a model called Post. On my index page i'm listing all the posts. I would like to have a voting button right next to each post that can add a point, no down voting.

For the button itself, i'd like to use this: https://github.com/masukomi/kudos

How do I connect it to this gem? https://github.com/ryanto/acts_as_votable

Was it helpful?

Solution

You'd need to provide some code, but you could handle the voting mechanism with your backend code, like this:

#config/routes.rb
resources :posts do
   match ":post_id", to: :vote, via: [:post, :delete], as: "vote"
end

#app/controllers/posts_controller.rb
def vote
    @post = Post.find(params[:post_id])
    @post.liked_by current_user 

    respond_to do |format|
        format.html
        format.js
    end
end

#app/views/items/vote.js.erb
alert("Thanks for your vote!");
//kudos button code here
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top