Hi All,
I am trying to pass values to ez_where to construct my conditions. I
need
to know how the params need to be formated for ez_where.
My search class looks like this:
def search
@display_ad = DisplayAd.new(params[:display_ad])
cond = Caboose::EZ::Condition.new do
pub_date == ‘@display_ad.pub_date’
io_number =~ ‘@display_ad.io_number’
end
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
127.0.0.1 - - [21/Feb/2006:22:31:46 PST] “GET /favicon.ico HTTP/1.1”
200 0
- -> /favicon.ico
2004-06-02
12345
pub_date = ? AND io_number LIKE ?
@display_ad.pub_date
@display_ad.io_number
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
Dave
David-
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 = DisplayAd.new(params[:display_ad])
cond = Caboose::EZ::Condition.new do
pub_date == display_ad.pub_date
io_number =~ display_ad.io_number
end
#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
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 Condition.new block and you will be fine.
Cheers-
-Ezra
On Tue, 2006-02-21 at 22:45 -0800, David W. wrote:
cond = Caboose::EZ::Condition.new do
127.0.0.1 - - [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
above.
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
table)
Craig