Overriding default_scope in Rails

后端 未结 4 1226
北恋
北恋 2020-12-13 07:09

In my Post.rb model, I have default_scope :conditions => {:deleted => \'false\'}

But if I try to run Post.find(:all, :conditions => \"del

4条回答
  •  醉梦人生
    2020-12-13 08:03

    with_exclusive_scope is protected, so you have to create a class method:

    def self.include_deleted_in
      Event.with_exclusive_scope { yield }
    end
    

    then in your controller call

    Post.include_deleted_in { Post.find(:all) }
    

提交回复
热议问题