How to use will_paginate and ambition together?

3 views
Skip to first unread message

szimek

unread,
Mar 19, 2008, 10:37:41 AM3/19/08
to ambition.rb
Hi,

I've already posted it in Ruby on Rails group, but I guess it should
be rather here.

I need to add filtering to my app. Long time ago I was using ez_where
plugin, but it seems that there's ambition now. I'm already using
will_paginate for pagination and was wondering if it's possible to
use
them together.

Also in ez_where I could do something like this:

cond = Caboose::EZ::Condition.new do
foo == 'bar' unless params[:filter][:country].blank?
baz <=> (1..5) if something
end

Is it possible to do something similar in ambition? I.e. if
params[:filter][:country] == "", I don't want to include it in the
condition.

Thanks for any tips

Oliver Steele

unread,
Mar 24, 2008, 7:25:54 AM3/24/08
to ambition.rb
On Mar 19, 10:37 am, szimek <szi...@gmail.com> wrote:
[snip -- I don't have an answer to the first part]
> Also in ez_where I could do something like this:
>
> cond = Caboose::EZ::Condition.new do
>   foo == 'bar' unless params[:filter][:country].blank?
>   baz <=> (1..5) if something
> end
>
> Is it possible to do something similar in ambition? I.e. if
> params[:filter][:country] == "", I don't want to include it in the
> condition.

I just had to this! You can move the guards outside the Ambition
block, and build the query incrementally:
cond = Condition.select { true }
cond = cond.select { |it| it.foo == 'bar' } unless params[:filter]
[:country].blank?
cond = cond.select { |it| it.baz <=> (1..5) } if something

This constructs an object that generates a single :conditions
expression, even though the expression is sourced in pieces.
Reply all
Reply to author
Forward
0 new messages