# Need syntax help for the conditions argument in the find (ie Active Record) method

**URL:** <https://www.ruby-forum.com/t/need-syntax-help-for-the-conditions-argument-in-the-find-ie-active-record-method/192721>\
**Category:** Rails\
**Created:** [August 4, 2010, 2:09pm UTC](https://www.ruby-forum.com/t/need-syntax-help-for-the-conditions-argument-in-the-find-ie-active-record-method/192721 "2010-08-04T14:09:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ct9a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ad7895/32.png) [@ct9a](https://www.ruby-forum.com/u/ct9a)\
**Post date:** [August 4, 2010, 2:09pm UTC](https://www.ruby-forum.com/t/need-syntax-help-for-the-conditions-argument-in-the-find-ie-active-record-method/192721/1 "2010-08-04T14:09:17Z")

</div>

hi guys

in relation to the “find” method in Active Record, can anyone tell me  
how to write the syntax for the following?

1. entries created within the past 2 hours, AND
2. entries that do not have a status of “Sold”

at the moment, i have the following and i still get a syntax error of  
“NoMethodError: undefined method `%’ for #Hash:0x000000083fa520”

```
@latest_entries = Books.find(:all,
  :conditions => [
    {
      :created_at => (Time.now - 6 ) .. (Time.now)
    },
    [
      'status_id != ?' => Status.find_by_name('sold')
    ]
  ],
  :limit => 20,
  :order => 'created_at DESC'
)

```

Can someone please help me in terms of the syntax for the conditions  
argument?

Thanks

---

<div class="post-metadata">

**Author:** ![ct9a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ad7895/32.png) [@ct9a](https://www.ruby-forum.com/u/ct9a)\
**Post date:** [August 4, 2010, 2:31pm UTC](https://www.ruby-forum.com/t/need-syntax-help-for-the-conditions-argument-in-the-find-ie-active-record-method/192721/2 "2010-08-04T14:31:32Z")

</div>

On Aug 4, 1:08 pm, ct9a [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> :order => 'created_at DESC'
> )
> 
> ```
> 
> Can someone please help me in terms of the syntax for the conditions  
> argument?

You can’t mix and match the hash form and the array form of conditions

- has to be all one or all the other.

Fred

---

<div class="post-metadata">

**Author:** ![ct9a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ad7895/32.png) [@ct9a](https://www.ruby-forum.com/u/ct9a)\
**Post date:** [August 4, 2010, 2:46pm UTC](https://www.ruby-forum.com/t/need-syntax-help-for-the-conditions-argument-in-the-find-ie-active-record-method/192721/3 "2010-08-04T14:46:11Z")

</div>

hi, Frederick,

I was hoping to be able to mix hash and array conditions.  
After all, in an array , we could have hash element conditions.

Anyway, your feedback along with my trials on the console further  
confirms that it cannot be done.

I have fixed the problem in another manner (ie. use a clause for  
“live” status entries only).

Thanks 🙂

Case closed 🙂
