百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
L

likeable

> 编程语言
开源

使用 Redis 可以使您的 Ruby 对象变得可爱

328 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

使用 Redis 可以使您的 Ruby 对象变得可爱

Use Redis to Make your Ruby objects Likeable!

I no longer use this gem in production (it was written for Gowalla), if you do and want to help me maintain it, let me know @schneems.

You like this

Likeable will allow your models to be liked by users, just drop a few lines of code into your model and you're good to go.

…

This library doesn't do dislikes, if you want something with more flexibility check out opinions.

Screencast

You can view a screencast of likeable in action on youtube. There is also an example Likeable rails application that you can use to follow along.

Setup

Gemfile:

gem 'likeable'

Next set up your Redis connection in initializers/likeable.rb:

ruby

    Likeable.setup do |likeable|
      likeable.redis  = Redis.new
    end

Then add the Likeable::UserMethods module to models/user.rb:

ruby

    class User
      include Likeable::UserMethods
    end

Finally add Likeable module to any model you want to be liked:

ruby

    class Comment
      include Likeable
    end

Rails Info

If you're using Likeable in Rails this should help you get started

controllers/likes_controller.rb

ruby

  class LikesController  'success'
    end

    def destroy
      target = Likeable.find_by_resource_id(params[:resource_name], params[:resource_id])
      current_user.unlike!(target)
      redirect_to :back, :notice => 'success'
    end
  end

config/routes.rb

ruby

    delete  'likes/:resource_name/:resource_id' => "likes#destroy", :as => 'like'
    post    'likes/:resource_name/:resource_id' => "likes#create",  :as => 'like'

helpers/like_helper.rb

ruby

    def like_link_for(target)
      link_to "like it!!", like_path(:resource_name => target  .class, :resource_id => target.id), :method => :post
    end

    def unlike_link_for(target)
      link_to "unlike it!!", like_path(:resource_name => target.class, :resource_id => target.id), :method => :delete
    end

Then in any view you can simply call the helper methods to give your user a link

ruby

    
      
    
      
    

Why

We 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.

           RedisRed            RedisRedi
        RedisRedisRedi       RedisRedisRedisR
      RedisRedisRedisRedi   RedisRedisRedisRedi
     RedisRedisRedisRedisRedisRedisRe       Redi
    RedisRedisRedisRedisRedisRedisRe         Redi
   RedisRedisRedisRedisRedisRedisRedisR       Redi
   RedisRedisRedisRedisRedisRedisRedisRedis      R
  RedisRedisRedisRedisRedisRedisRedisRedisRedi  Red
  RedisRedisRedisRedisRedisRedisRedisRedisRedisRe R
  RedisRedisRedisRedisRedisRedisRedisRedisRedisRedi
  RedisRedisRedisRedisRedisRedisRedisRedisRedisRedi
   RedisRedisRedisRedisRedisRedisRedisRedisRedisRe
    RedisRedisRedisRedisRedisRedisRedisRedisRedis
      RedisRedisRedisRedisRedisRedisRedisRedisRe
        RedisRedisRedisRedisRedisRedisRedisRe
           RedisRedisRedisRedisRedisRedisR
              RedisRedisRedisRedisRedis
                RedisRedisRedisRedis
                   RedisRedisRed
                     RedisRedi
                       RedisR
                        Redi
                         Re

Authors

Richard Schneeman for Gowalla <3

Contribution

Fork away. If you want to chat about a feature idea, or a question you can find me on the twitters @schneems. Put any major changes into feature branches. Make sure all tests stay green, and make sure your changes are covered.

licensed under MIT License Copyright (c) 2011 Schneems. See LICENSE.txt for further details.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言