Argument Error: The scope body needs to be callable

前端 未结 4 1051
南方客
南方客 2020-12-24 01:24

I\'m working through the \'Ruby On Rails 3 Essential Training\' and have received a problem when using name scopes. When finding records and using queries withing the Rails

4条回答
  •  盖世英雄少女心
    2020-12-24 01:58

    The scope's body needs to be wrapped in something callable like a Proc or Lambda:

    scope :visible, -> {
      where(:visible => true)
    }
    

    The reason for this is that it ensures the contents of the block is evaluated each time the scope is used.

提交回复
热议问题