Skip to content

Instantly share code, notes, and snippets.

@joshsmith
Created November 12, 2012 02:39
Show Gist options
  • Select an option

  • Save joshsmith/4057212 to your computer and use it in GitHub Desktop.

Select an option

Save joshsmith/4057212 to your computer and use it in GitHub Desktop.
= link_to(comment_create_comment_vote_path(@comment, :comment_vote => { :comment_id => @comment.id, :user_id => current_user.id, :vote_flag => true }), {:method => :post, :remote => true, :class => 'like-comment'}) do
%i.icon-thumbs-up
%span.helpful-text Mark helpful
class CommentVotesController < ApplicationController
load_and_authorize_resource
def create
@vote = CommentVote.new(params[:comment_vote])
@vote.save
respond_to do |format|
format.html { redirect_to(@vote) }
format.js { render :json => @vote, :status => :created, :location => @vote }
end
end
end
$('.like-comment').on('ajax:success', function(event, xhr, data, status) {
console.log(event, xhr, data, status);
$(this).removeClass('like-comment').addClass('unlike-comment')
.children('.helpful-text').text('You marked helpful');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment