Rails 4 - undefined method `call' when doing a simple query

前端 未结 1 1576
被撕碎了的回忆
被撕碎了的回忆 2020-12-14 19:36

I\'m new to Rails but this seems pretty straightforward. I have a model called Game generated like this:

rails generate model Game name:string          


        
相关标签:
1条回答
  • 2020-12-14 20:01

    Rails 4+ requires named scopes to be a lambda and not just a simple Relation.

    Change the old version

    scope :active, where(is_active: true)
    

    to the lambda version

    scope :active, lambda { where(is_active: true) }
    

    or even shorter to

    scope :active, -> { where(is_active: true) }
    

    For more information about named scopes and how to pass parameters, I suggest reading about Scopes in the Rails Guide

    0 讨论(0)
提交回复
热议问题