【问题标题】:Using Activerecord with Redis is giving me an error将 Activerecord 与 Redis 一起使用给了我一个错误
【发布时间】:2011-10-03 22:38:45
【问题描述】:

我只是想了解本教程

http://jimneath.org/2011/03/24/using-redis-with-ruby-on-rails.html#redis_and_rails

当我将此代码放入 lib/user.rb 或 app/models/user.rb 时:

class User < ActiveRecord::Base
  # follow a user
  def follow!(user)
    @redis.multi do
...

我收到此错误:

ActiveRecord::StatementInvalid: Could not find table 'users'
    from /Users/jeremysmith/.rvm/gems/ruby-1.9.2-p180/gems/activerecord- 3.0.5/lib/active_record/connection_adapters/sqlite_adapter.rb:295:in `table_structure'

请注意,@redis 正在工作,而我根本没有使用 sqlite,所以我不确定为什么要引用它。我的 Gemfile 中确实包含 sqlite,但在我的项目中没有其他地方。

【问题讨论】:

    标签: ruby-on-rails ruby activerecord redis


    【解决方案1】:

    您仍然需要一个普通的 sqlite / mysql 数据库来存储您的用户,它只是您存储在 redis 中的某些部分。确保您有正确的迁移并发出rake db:migrate

    我还注意到您使用 @redis 而不是 $redis 您确定它按预期工作吗?

    【讨论】:

    • 我把它改成了@redis,因为我讨厌美元符号! Thx,没有注意到里面的sqlite。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-09
    • 2015-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多