【问题标题】:How to get counter_cache / invitations_count working for devise invitable Rails gem?如何让 counter_cache /invitations_count 为设计可邀请的 Rails gem 工作?
【发布时间】:2016-01-28 03:50:39
【问题描述】:

我在我的 Rails 应用程序中使用了可邀请的设计。邀请计数列(应该是已发送邀请的计数器缓存)保持为零。

initializers/devise.rb

# The column name used for counter_cache column. If this is nil,
# the #invited_by association is declared without counter_cache.
# Default: nil
config.invited_by_counter_cache = :invitations_count

以上是宝石的到达方式。我取消了启用计数器的最后一行的注释。

我已经阅读了设计邀请 Github 问题页面,搜索了 SO 和 Google,并尝试在我的应用程序的各个地方摆弄。宝石的其余部分工作正常并发送邀请但没有计数器。

关于如何解决的想法?谢谢!

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 devise devise-invitable


    【解决方案1】:

    我不知道这是否是您的问题,但我个人没有正确使用此功能。此列保存某人发送的邀请数,而不是某人收到的邀请数。

    您必须将第二个参数传递给#invite!方法来触发谁邀请的记录上的计数器缓存。

    Link to the test

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多