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

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

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 =&gt;  \[
    \{
      :created\_at =&gt; \(Time\.now \- 6 \) \.\. \(Time\.now\)
    \},
    \[
      &#39;status\_id \!= ?&#39;  =&gt; Status\.find\_by\_name\(&#39;sold&#39;\)
    \]
  \],
  :limit        =&gt;  20,
  :order        =&gt; &#39;created\_at DESC&#39;
\)

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

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 :slight_smile:

Case closed :slight_smile: