开发者

Check if a user is a regular user

开发者 https://www.devze.com 2023-03-21 20:49 出处:网络
I have the following code: class User < ActiveRecord::Base named_scope :regular_users, :conditions => { :is_developer => false }

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

0

精彩评论

暂无评论...
验证码 换一张
取 消