Rails: Why is with_exclusive_scope protected? Any good practice on how to use it?

后端 未结 3 1031
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-04 15:35

Given a model with default_scope to filter all outdated entries:

# == Schema Information
#
#  id          :integer(4)      not null, primary key
#           


        
3条回答
  •  温柔的废话
    2020-12-04 16:05

    You must encapsulate the protected method inside a model method, something like:

    class Ticket < ActiveRecord::Base
      def self.all_tickets_from(user)
        with_exclusive_scope{user.tickets.find(:all)}
      end
    end
    

提交回复
热议问题