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 Feb 21, 2006, at 10:45 PM, David Watts wrote:
> 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
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>