# Fun with ez\_where

**URL:** <https://www.ruby-forum.com/t/fun-with-ez-where/101107>\
**Category:** Rails\
**Created:** [August 3, 2006, 12:56pm UTC](https://www.ruby-forum.com/t/fun-with-ez-where/101107 "2006-08-03T12:56:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![olbrich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/5f9b8f/32.png) [@olbrich](https://www.ruby-forum.com/u/olbrich)\
**Post date:** [August 3, 2006, 12:56pm UTC](https://www.ruby-forum.com/t/fun-with-ez-where/101107/1 "2006-08-03T12:56:13Z")

</div>

I’ve been trying to use the ez\_where plugin to create a dynamic finder.  
The structure looks somehing like this…

=== controller ===

def list  
attribute\_filter = params[:filter]  
@filter = Caboose::EZ::Condition.new :table do  
attribute \<=\> attribute\_filter if attribute\_filter  
end

# 

… do the find with the @filter

# 

end

=== view ===  
…  
\<%= link\_to ‘Add filter’, {:filter=\>value}.merge(params) %\>

this works fine, but there are some weird things here.  
Notice that the structure of the ‘list’ function is odd. I first tried  
this…

def list  
@filter = Caboose::EZ::Condition.new :table do  
attribute \<=\> params[:filter] if params[:filter]  
end  
end

But this doesn’t work. It doesn’t throw an error, but it adds a clause  
to the @filter like this…

- !ruby/object:Caboose::EZ::Clause  
name: params  
table\_prefix: table.  
test: :[]  
value: :filter

and otherwise doesn’t behave as you might expect.

Sooo… if want to use the ez\_where plugin with conditions, be careful.

There’s probably a way around this, hopefully Ezra has some nifty trick  
for making this work as expected.

\_Kevin  
[www.sciwerks.com](http://www.sciwerks.com)

---

<div class="post-metadata">

**Author:** ![olbrich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/5f9b8f/32.png) [@olbrich](https://www.ruby-forum.com/u/olbrich)\
**Post date:** [August 3, 2006, 2:23pm UTC](https://www.ruby-forum.com/t/fun-with-ez-where/101107/2 "2006-08-03T14:23:13Z")

</div>

On Aug 2, 2006, at 10:00 AM, Kevin O. wrote:

> end  
> Notice that the structure of the ‘list’ function is odd. I first  
> clause  
> Sooo… if want to use the ez\_where plugin with conditions, be  
> careful.
> 
> There’s probably a way around this, hopefully Ezra has some nifty  
> trick  
> for making this work as expected.
> 
> \_Kevin  
> [www.sciwerks.com](http://www.sciwerks.com)

Kevin-

```
This was a problem in an older version of the plugin. It is fixed in

```

the new version. I can tell you are using the old one because what  
used to be this: Caboose::EZ::Condition.new ids now  
EZ::Where::Condition.new. Anyways grab the latest version where this  
is fixed. Also note that you do not have to do params[:filter] if  
params[:filter]. You can drop the if params[:filter] and the plugin  
will exclude that condition if params[:filter] is nil. That way you  
don’t have to do all those ugly if’s or unless’s. Grab the latest  
version form here:

$ script/plugin install svn://rubyforge.org//var/svn/ez-where

Cheers-  
-Ezra

---

<div class="post-metadata">

**Author:** ![olbrich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/5f9b8f/32.png) [@olbrich](https://www.ruby-forum.com/u/olbrich)\
**Post date:** [August 3, 2006, 2:23pm UTC](https://www.ruby-forum.com/t/fun-with-ez-where/101107/3 "2006-08-03T14:23:46Z")

</div>

On Wednesday, August 02, 2006, at 5:14 PM, Kevin O. wrote:

> > > === view ===  
> > > attribute \<=\> params[:filter] if params[:filter]  
> > > test: :[]
> > 
> > EZ::Where::Condition.new. Anyways grab the latest version where this  
> > -Ezra
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

BTW: the Readme file in the new version still uses the  
Caboose::EZ::Condition notation

\_Kevin  
[www.sciwerks.com](http://www.sciwerks.com)

---

<div class="post-metadata">

**Author:** ![olbrich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/5f9b8f/32.png) [@olbrich](https://www.ruby-forum.com/u/olbrich)\
**Post date:** [August 3, 2006, 2:23pm UTC](https://www.ruby-forum.com/t/fun-with-ez-where/101107/4 "2006-08-03T14:23:46Z")

</div>

> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

Thanks, fixed now.

-Ezra

---

<div class="post-metadata">

**Author:** ![olbrich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/5f9b8f/32.png) [@olbrich](https://www.ruby-forum.com/u/olbrich)\
**Post date:** [August 3, 2006, 2:23pm UTC](https://www.ruby-forum.com/t/fun-with-ez-where/101107/5 "2006-08-03T14:23:46Z")

</div>

On Wednesday, August 02, 2006, at 10:06 AM, Ezra Z. wrote:

> > @filter = Caboose::EZ::Condition.new :table do
> > 
> > But this doesn’t work. It doesn’t throw an error, but it adds a \> clause  
> > Sooo… if want to use the ez\_where plugin with conditions, be \> careful.
> 
> $ script/plugin install svn://rubyforge.org//var/svn/ez-where  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

Great Ezra!

One other question… if you call .to\_sql on an empty Condition, does it  
return something like ‘1’ now. The older version doesn’t.

FWIW, I used rapt to download it. I’m not sure where it got it from.

\_Kevin  
[www.sciwerks.com](http://www.sciwerks.com)

---

<div class="post-metadata">

**Author:** ![olbrich](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/5f9b8f/32.png) [@olbrich](https://www.ruby-forum.com/u/olbrich)\
**Post date:** [August 15, 2006, 2:21pm UTC](https://www.ruby-forum.com/t/fun-with-ez-where/101107/6 "2006-08-15T14:21:34Z")

</div>

Hi Ezra,

ez-where rocks! I recently started using it with Ajax scaffold and it  
works  
great and keeps my controller code sparkling clean.

Thanks!
