Topic: simplyfy my code pls

hi....

is it possible to refactor my below code.....

@total_users_count = UserInfo.count(:all, :select => 'id', :conditions => ["login !=?",'admin'])
     
     @total_disabled_users = UserInfo.count(:all, :select => 'id', :conditions => ["active_status = ? and login !=? ","0",'admin'] )
     
     @total_users_online = UserInfo.count(:all, :select => 'id', :conditions => ["online_status = ? and login !=?and default_status = ?","1","admin","Online"])
     
     @total_users_offline = UserInfo.count(:all, :select => 'id', :conditions => ["online_status = ? and login != ? and active_status != ?","0","admin","0"])
     
     @total_users_meeting = UserInfo.count(:all, :select => 'id', :conditions => ["online_status = ? and login !=? and default_status = ?","1","admin","Meeting"])
     
     @total_users_busy = UserInfo.count(:all, :select => 'id', :conditions => ["online_status = ? and login !=? and default_status = ?","1","admin","Busy"])
     
     @total_users_away = UserInfo.count(:all, :select => 'id', :conditions => ["online_status = ? and login != ?and default_status = ?","1","admin","Away"])

Re: simplyfy my code pls

You can use named_scopes to simplify your code.

http://railscasts.com/episodes/108-named-scope

Re: simplyfy my code pls

Hi..
thanks for the reply...
i never used named_scope....

could give me an example...

Re: simplyfy my code pls

newb wrote:

Hi..
thanks for the reply...
i never used named_scope....

could give me an example...

Go look it up.

Re: simplyfy my code pls

solved

Re: simplyfy my code pls

Cool. Learning how to researcht hings for yourself is an important part of programming.