Using ez_where


Hi All,

I am trying to pass values to ez_where to construct my conditions. I
to know how the params need to be formated for ez_where.

My search class looks like this:

def search
@display_ad =[:display_ad])
cond = do
pub_date == ‘@display_ad.pub_date
io_number =~ ‘@display_ad.io_number
puts @display_ad.pub_date
puts @display_ad.io_number
puts cond.to_sql
#display_ad = DisplayAd.find(:all, conditions => cond.to_sql )
#render :action => ‘list’
end - - [21/Feb/2006:22:31:46 PST] “GET /favicon.ico HTTP/1.1”
200 0

  • -> /favicon.ico
    pub_date = ? AND io_number LIKE ?

The console shows the values being passed to the class but I
don’t know what will give ez_where the values properly.

Thanks for any help




There is a small impedance mis-match with @instance vars not working

inside a Condition block like you are doing. It happens because
@ivars are tied to self and self refers to a different class inside
the Condition block.

The way to get around this is to just use normal local vars without

the @ sign, like so:

def search
display_ad =[:display_ad])
cond = do
pub_date == display_ad.pub_date
io_number =~ display_ad.io_number
#puts display_ad.pub_date
#puts display_ad.io_number
#puts cond.to_sql
@display_ad = DisplayAd.find(:all, conditions => cond.to_sql )
render :action => ‘list’

That should work fine. I haven't found a way around that limitation

yet : / But since you are only using the first display_ad to buidl
the conditions with it should be just a local var anyway so I think
its not too big of a problem. Just remember that you can’t use @ivars
inside the block and you will be fine.



On Tue, 2006-02-21 at 22:45 -0800, David W. wrote:

 cond = do - - [21/Feb/2006:22:31:46 PST] “GET /favicon.ico HTTP/1.1”

Thanks for any help

I found that I didn’t want to put variables inside of quotes as you did

pub_date == @display_ad.pub_date
io_number =~ @display_ad.io_number

(assuming that pub_date and io_number are columns in your display_ads