2014-02-08 266 views

回答

1

你需要提供一些代碼,但你可以處理的投票機制與你的後端代碼,就像這樣:

#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