Forum: Ruby on Rails Using ez_where

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
David W. (Guest)
on 2006-02-22 08:47
(Received via mailing list)
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
Ezra Z. (Guest)
on 2006-02-22 09:28
(Received via mailing list)
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
Craig W. (Guest)
on 2006-02-22 16:41
(Received via mailing list)
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
This topic is locked and can not be replied to.