Fun with ez_where

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

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

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

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
[email protected]
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

Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

Thanks, fixed now.

-Ezra

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

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

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!