glarkou
glarkou

Reputation: 7101

Check if a user is a regular user

I have the following code:

class User < ActiveRecord::Base
  named_scope :regular_users, :conditions => { :is_developer => false }
end

How can I change this code to return if a specific user is a regular user (has :is_developer => false ) instead of a list of all regular users?

Thanks

Upvotes: 0

Views: 52

Answers (1)

bassneck
bassneck

Reputation: 4043

You can just check User.find(1).is_developer? (actually it will work even without the ?) To check the opposite, use ! User.find(1).is_developer? or not User.find(1).is_developer

or put this in a model method like

def is_regular?
  ! is_developer?
end

I doubt that you can get boolean value with scope.

btw, with Rails3 you can use scope instead of named_scope

Upvotes: 2

Related Questions