Search code examples
ruby-on-railsruby-on-rails-2

How to use an array in the condition as a filter - Ruby Rails


array_users = ["3581", "3592", "3665", "3730"]

@records = Model.find(
           :all, 
           :order => 'date desc', 
           :group => :date, 
           :conditions => {
                 :client_id => current_user.client.id,  
                 :user_id is present in array_users # <------------------
           })

How would one make certain that only the records returned have a user_id that is present in array_users using Rails 2.3.9?


Solution

  • :conditions => {
      :client_id => current_user.client.id,  
      :user_id => array_users
    })
    

    See the guide for all the possibilities with the hash conditions.