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 开发者_如何学Cis a regular user (has :is_developer => false ) instead of a list of all regular users?
Thanks
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
精彩评论