Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you find all scope names for a given class in Ruby on Rails?

For example, given I defined scopes for the class Task, is there a way to find all scope names for that class?

I'm looking for something like:

Task.scope_names

which would output something like:

["completed", "uncompleted", "pending"]

Any ideas on how to do so?

like image 362
sjsc Avatar asked Dec 10 '14 09:12

sjsc


1 Answers

According to docs such methods as

Model.scopes 
#=> outputs all scopes

and

Model.send(:valid_scope_name?, scope_name)
#=> takes scope name as an argument and returns either true or false

are no longer available since Rails 3.1.0.

like image 128
Andrey Deineko Avatar answered Sep 19 '22 18:09

Andrey Deineko