Created
November 15, 2009 00:49
-
-
Save peteroome/234881 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // application.js | |
| $(function(){ | |
| $('body').removeClass('js-disabled').addClass('js-enabled'); | |
| $('#i_like_this').incrementILikeCount(); | |
| }); | |
| $.fn.incrementILikeCount = function() { | |
| return this.each(function(){ | |
| var linkAction = $(this).attr('href') | |
| $(this).click(function(){ | |
| var commentCount = $('h3#article_like_count span') | |
| var linkText = $(this).parent(); | |
| $.get(linkAction,function(){ | |
| commentCount.text(parseInt(commentCount.text(),10)+1); | |
| linkText.fadeOut('fast',function(){ | |
| $(this).text('Thanks for your vote'); | |
| }); | |
| linkText.fadeIn('fast'); | |
| }); | |
| return false; | |
| }); | |
| }); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // article_controller.rb | |
| def like | |
| article = Article.find(params[:id]) | |
| article.update_attribute(:likes, (article.likes + 1)) | |
| render :nothing => true | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //articles => show.html.erb | |
| <%= content_tag :h3, link_to("I like this!", {:controller => :articles, :action => :like, :id => @article}, :id => "i_like_this") %> | |
| <%= content_tag :h3, pluralize_likes(@article.likes), :class => "comment_count", :id => "article_like_count" %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment