How to use Find with conditions?

Recently I read that the following find

Type 1

Post.find(:first, :conditions => [‘status = ? and active = ?’, 1, 1])

can be written as

Type 2

Post.find(:first, :conditions => { :status => 1, :active => 1 })

But how do I include LIKE operator in Type 2 find?

thanks

I never used but

this may work Post.find(:first,:conditions[ ‘status like ? and active
like
?’, 1, 1])

On Sun, Jul 12, 2009 at 5:07 PM, Rails L. <

sorry , conditions should be hash

Post.find(:first,:conditions=>[ ‘status like ? and active like ?’, 1,
1])

On Sun, Jul 12, 2009 at 5:14 PM, Narendra sisodiya
<[email protected]

2009/7/12 Rails L. [email protected]:


Post.find(:first, :conditions => { :status => 1, :active => 1 })

But how do I include LIKE operator in Type 2 find?

I believe that you cannot use LIKE in the Type 2 find.

Colin

I like the type 2. But your example is a better candidate for named
scope.
like defining named scope ‘active’ and using like,
Post.active

On Jul 12, 5:37 pm, Rails L. [email protected]