Search code examples
ruby-on-railsrails-migrations

what does default_scope -> { kept } in rails means?


I am new to rails world. In one of the existing rails project I am working, I see a line in a model class as mentioned below. Can someone please tell me what does this signify. I tried searching documentation but couldn't find "kept" keyword anywhere.

default_scope -> { kept }


Solution

  • From what I get, this is a scope that might be provided by a gem that allows you to "discard" records (instead of deleting them). The default scope is set to only return results that are kept (i. e. not discarded). Of course the functionality could also be developed manually but then you'd find the code in your project (e. g. in the model or a concern).

    A popular gem to achieve this would be https://github.com/jhawthorn/discard (not affiliated with it) which effectively uses kept. Maybe check your Gemfile what gems your project uses and search their docs for this.