【发布时间】:2014-12-31 19:44:26
【问题描述】:
您好,我在这里有点困惑,因为我正在尝试使用范围,但似乎无法使其工作。
我现在像这样在我的模型部分使用它。
has_many :friends, through: :user_friendships,
scope -> {where(user_friendships: { state: 'accepted' })}
在我像这样从 turorials 中使用它之前,我发现它已被贬低,不得不重新调整我上面使用的代码,但问题是它也遇到了错误
has_many :friends, through: :user_friendships,
conditions: { user_friendships: { state: 'accepted' }}
这是我在终端使用第一行代码和第二行代码时遇到的错误
/home/simplybel/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.6/lib/active_support/core_ext/hash/keys.rb:71:in `block in assert_valid_keys': Unknown key: :scope. Valid keys are: :class_name, :class, :foreign_key, :validate, :autosave, :table_name, :before_add, :after_add, :before_remove, :after_remove, :extend, :primary_key, :dependent, :as, :through, :source, :source_type, :inverse_of, :counter_cache, :join_table (ArgumentError)
如果有人可以帮助我解决这个问题,那将非常感谢!我也是rails中的菜鸟,所以我可能无法正确理解您可能在答案中输入的语法,所以请您帮忙。让它对菜鸟友好,谢谢!
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4.1