{"id":22558628,"url":"https://github.com/jschwindt/likeable","last_synced_at":"2025-03-28T11:42:14.565Z","repository":{"id":10664953,"uuid":"12898668","full_name":"jschwindt/Likeable","owner":"jschwindt","description":"This is a fork of the following missing repository: https://github.com/amrnt/Likeable","archived":false,"fork":false,"pushed_at":"2013-09-17T15:11:14.000Z","size":156,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-02T12:17:14.056Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jschwindt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"license.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-09-17T15:10:48.000Z","updated_at":"2013-12-22T05:28:57.000Z","dependencies_parsed_at":"2022-09-22T21:03:01.404Z","dependency_job_id":null,"html_url":"https://github.com/jschwindt/Likeable","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jschwindt%2FLikeable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jschwindt%2FLikeable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jschwindt%2FLikeable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jschwindt%2FLikeable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jschwindt","download_url":"https://codeload.github.com/jschwindt/Likeable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246025918,"owners_count":20711575,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-07T20:16:22.028Z","updated_at":"2025-03-28T11:42:14.542Z","avatar_url":"https://github.com/jschwindt.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"Use Redis to Make your Ruby objects Likeable!\n======\n\nYou like this\n-------------\nLikeable is the easiest way to allow your models to be liked by users, just drop a few lines of code into your model and you're good to go.\n\n```ruby\n\n    class Comment\n      include Likeable\n\n      # ...\n    end\n\n    class User\n      include Likeable::UserMethods\n\n      # ...\n    end\n\n    Likeable.setup do |likeable|\n      likeable.redis   = Redis.new\n    end\n\n    comment = Comment.find(15)\n    comment.like_count                  # =\u003e 0\n    current_user.like!(comment)         # =\u003e #\u003cLikeable::Like ... \u003e\n    comment.like_count                  # =\u003e 1\n    comment.likes                       # =\u003e [#\u003cLikeable::Like ... \u003e]\n    comment.likes.last.user             # =\u003e #\u003cUser ... \u003e\n    comment.likes.last.created_at       # =\u003e Wed Jul 27 19:34:32 -0500 2011\n\n    comment.liked_by?(current_user)     # =\u003e true\n\n    current_user.all_liked(Comment)     # =\u003e [#\u003cComment ...\u003e, ...]\n\n    liked_comment = Likeable.find_by_resource_id(\"Comment\", 15)\n    liked_comment == comment            # =\u003e true\n\n```\nAnd it also allow your models to be disliked by users:\n\n```ruby\n    comment = Comment.find(15)\n    comment.dislike_count                 # =\u003e 0\n    current_user.dislike!(comment)        # =\u003e #\u003cLikeable::Dislike ... \u003e\n    comment.dislike_count                 # =\u003e 1\n    comment.dislikes                      # =\u003e [#\u003cLikeable::Dislike ... \u003e]\n    comment.dislikes.last.user            # =\u003e #\u003cUser ... \u003e\n    comment.dislikes.last.created_at      # =\u003e Thu Nov 10 06:16:14 +0200 2011\n\n    comment.disliked_by?(current_user)    # =\u003e true\n\n    current_user.all_disliked(Comment)    # =\u003e [#\u003cComment ...\u003e, ...]\n\n\n    # Notice `plusminus` method that equals to (like_count - dislike_count)\n    comment = Comment.find(15)\n    comment.plusminus                     # =\u003e 0\n\n    current_user.dislike!(comment)\n    comment.plusminus                     # =\u003e -1\n    comment.disliked_by?(current_user)    # =\u003e true\n\n    current_user.like!(comment)\n    comment.plusminus                     # =\u003e 1\n    comment.liked_by?(current_user)       # =\u003e true\n\n    current_user_2.like!(comment)\n    comment.plusminus                     # =\u003e 2\n    comment.liked_by?(current_user_2)     # =\u003e true\n\n    # Notice `cancel_like!` method\n    current_user.cancel_like!(comment)\n    comment.plusminus                     # =\u003e 1\n    comment.liked_by?(current_user)       # =\u003e false\n    comment.disliked_by?(current_user)    # =\u003e false\n\n```\n\n## Screencast\n\nYou can view a [screencast of likeable in action on youtube](http://youtu.be/iJoMXUQ33Jw?hd=1). There is also an example [Likeable rails application](https://github.com/schneems/likeable_example) that you can use to follow along.\n\n\n\nSetup\n=======\nGemfile:\n\n    gem 'likeable'\n\nNext set up your Redis connection in initializers/likeable.rb:\n\n```ruby\n\n    Likeable.setup do |likeable|\n      likeable.redis  = Redis.new\n    end\n```\n\nThen add the `Likeable::UserMethods` module to models/user.rb:\n\n```ruby\n\n    class User\n      include Likeable::UserMethods\n    end\n```\n\nFinally add `Likeable` module to any model you want to be liked:\n\n```ruby\n\n    class Comment\n      include Likeable\n    end\n```\n\n## Rails Info\nIf you're using Likeable in Rails this should help you get started\n\n controllers/likes_controller.rb\n\n```ruby\n\n  class LikesController \u003c ApplicationController\n\n    def create_like\n      target = Likeable.find_by_resource_id(params[:resource_name], params[:resource_id])\n      current_user.like!(target)\n      redirect_to :back, :notice =\u003e 'successfully liked'\n    end\n\n    def create_dislike\n      target = Likeable.find_by_resource_id(params[:resource_name], params[:resource_id])\n      current_user.dislike!(target)\n      redirect_to :back, :notice =\u003e 'successfully disliked'\n    end\n\n    def cancel_like\n      target = Likeable.find_by_resource_id(params[:resource_name], params[:resource_id])\n      current_user.cancel_like!(target)\n      redirect_to :back, :notice =\u003e 'successfully canceled'\n    end\n  end\n\n```\n\nconfig/routes.rb\n\n```ruby\n\n    match 'likes/:resource_name/:resource_id/like' =\u003e \"likes#create_like\",       :as =\u003e :like\n    match 'likes/:resource_name/:resource_id/dislike' =\u003e \"likes#create_dislike\", :as =\u003e :dislike\n    match 'likes/:resource_name/:resource_id/cancel' =\u003e \"likes#cancel_like\",         :as =\u003e :cancel_like\n\n```\n\nhelpers/like_helper.rb\n\n```ruby\n\n    def like_link_for(target)\n      link_to \"like it!\", like_path(:resource_name =\u003e target.class, :resource_id =\u003e target.id)\n    end\n\n    def dislike_link_for(target)\n      link_to \"dislike it!\", dislike_path(:resource_name =\u003e target.class, :resource_id =\u003e target.id)\n    end\n\n    def cancel_like_link_for(target)\n      link_to \"cancel like!\", cancel_like_path(:resource_name =\u003e target.class, :resource_id =\u003e target.id)\n    end\n\n```\n\nThen in any view you can simply call the helper methods to give your user a link\n\n```ruby\n\n    \u003c%- if @user.likes? @comment || @user.dislikes? @comment -%\u003e\n      \u003c%- if @user.likes? @comment -%\u003e\n        \u003c%= dislike_link_for @comment  %\u003e\n      \u003c%- else -%\u003e\n        \u003c%= like_link_for @comment %\u003e\n      \u003c%- end -%\u003e\n      \u003c%= cancel_like_link_for @comment %\u003e\n    \u003c%- end -%\u003e\n\n\n```\n\nWhy\n===\n\nWe chose Redis because it is screaming fast, and very simple to work with. By using redis for likeable we take load off of our relational database and speed up individual calls retrieve information about the \"liked\" state of an object. If you're not using redis in production, and don't want to, there are many other great liking/voting libraries out there such as [thumbs up](https://github.com/brady8/thumbs_up).\n\n\n               RedisRed            RedisRedi\n            RedisRedisRedi       RedisRedisRedisR\n          RedisRedisRedisRedi   RedisRedisRedisRedi\n         RedisRedisRedisRedisRedisRedisRe       Redi\n        RedisRedisRedisRedisRedisRedisRe         Redi\n       RedisRedisRedisRedisRedisRedisRedisR       Redi\n       RedisRedisRedisRedisRedisRedisRedisRedis      R\n      RedisRedisRedisRedisRedisRedisRedisRedisRedi  Red\n      RedisRedisRedisRedisRedisRedisRedisRedisRedisRe R\n      RedisRedisRedisRedisRedisRedisRedisRedisRedisRedi\n      RedisRedisRedisRedisRedisRedisRedisRedisRedisRedi\n       RedisRedisRedisRedisRedisRedisRedisRedisRedisRe\n        RedisRedisRedisRedisRedisRedisRedisRedisRedis\n          RedisRedisRedisRedisRedisRedisRedisRedisRe\n            RedisRedisRedisRedisRedisRedisRedisRe\n               RedisRedisRedisRedisRedisRedisR\n                  RedisRedisRedisRedisRedis\n                    RedisRedisRedisRedis\n                       RedisRedisRed\n                         RedisRedi\n                           RedisR\n                            Redi\n                             Re\nAuthors\n=======\n[Richard Schneeman](http://schneems.com) for [Gowalla](http://gowalla.com) \u003c3\n\n\nContribution\n============\n\nFork away. If you want to chat about a feature idea, or a question you can find me on the twitters [@schneems](http://twitter.com/schneems).  Put any major changes into feature branches. Make sure all tests stay green, and make sure your changes are covered.\n\n\nlicensed under MIT License\nCopyright (c) 2011 Schneems. See LICENSE.txt for\nfurther details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjschwindt%2Flikeable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjschwindt%2Flikeable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjschwindt%2Flikeable/lists"}