I am on rails 3.2.21, ruby version is 2.0
My requirement is to have role based conditional default scope for a particular model. eg
consider role variable as an attribute of logged in user
if role == 'xyz'
default_scope where(is_active: false)
elsif role == 'abc'
default_scope where(is_active: true)
end
Nothing is impossible in programming.
Using
default_scopeis a bad idea in general (lots of articles are written on the topic).If you insist on using current user's atribute you can pass it as an argument to scope:
And then use it as follows:
Sidenote: Rails 3.2.x - seriously?...