Trying various things here to eliminate this problem. In my dyanmic search ,
if no search criteria is selected then all records are returned. It''s
not
what I want. By the way this is an observe_form. Help is greatly
appreciated.
Here is the controller -
def list
category_id = params[:category_id]
state_id = params[:state_id]
term_id = params[:term_id]
city = params[:city]
title = params[:title]
pq = Position.query # I''m using the plugin CriteriaQuery
pq.category_id_in(params[:category_id])
unless(params[:category_id]|| "").empty?
pq.state_id_in(params[:state_id]) unless(params[:state_id]||
"").empty?
pq.term_id_in(params[:term_id]) unless(params[:term_id]||
"").empty?
pq.city_in(params[:city].split(",")) unless(params[:city]||
"").empty?
pq.title_in(params[:title].split(",")) unless(params[:title]||
"").empty?
pp pq
@positions = pq.find
render :partial => "positions_list", :layout => false
end
end
Here is the observe_form:# in the possibility that I can somehow enforce it
here to not return any records in the event nothing is selected
# I''m also showing my partial down
below
<form id="asearch">
<fieldset><legend>Category</legend>
<select name=category_id[] size="4" multiple = "multiple"
id = ''cat''><%options_from_collection_for_select
@categories, :id, :name, :prompt => true
%></select></fieldset>
<fieldset><legend>State</legend>
<select name=state_id[] size="4" multiple = "multiple" id
= ''stat''><%options_from_collection_for_select @states,
:id, :name
%></select></fieldset>
<fieldset><legend>Terms</legend>
<select name=term_id[] size="4" multiple = "multiple" id
= ''term''><%options_from_collection_for_select @terms,
:id, :name %></select></fieldset>
<fieldset><legend>Title</legend>
<input type="text" id="title" name="title"
size="10" id = ''title''
/></fieldset>
<fieldset><legend>City</legend>
<input type="text" id="city" name="city"
size="10" id = ''city'' /></fieldset>
</form>
</div>
<%= image_tag("roller.gif",
:align => ''center'',
:border => 0,
:id => "roller",
:style => "display: none;") %>
<%= observe_form "asearch",
:frequency => 0.5,
:update => ''table'',
:before =>
"Element.show(''roller'')",
:success =>
"Element.hide(''roller'')",
:url => ''list'' %>
<div id="partb">
<div id="table">
</div>
</div>
Partial:
<% if @positions == nil %>
<h1><%="Enter search criteria"%></h1>
<% elsif @positions.size == 0 %>
<h1><%="No jobs found using current search
criteria"%></h1>
<% else %>
<table>
<thead>
<td>Title</td>
<td>Category</td>
<td>Location</td>
<td>Terms</td>
</thead>
<tbody>
<% @positions.each do |p| %>
<tr class="<%= cycle("even","odd")
%>">
<td style="white-space: nowrap"><%= p.title
%></td>
<td style="white-space: nowrap"><%= p.category.name
%></td>
<td style="white-space: nowrap"><%= p.city %>-<%=
p.state.name %></td>
<td style="white-space: nowrap"><%= p.term.name
%></td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
--
http://en.wikipedia.org/wiki/Dark_ambient
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2006-Oct-15 12:24 UTC
Re: How to stop all records from being returned
Hi -- On Sun, 15 Oct 2006, Dark Ambient wrote:> Trying various things here to eliminate this problem. In my dyanmic search , > if no search criteria is selected then all records are returned. It''s not > what I want. By the way this is an observe_form. Help is greatly > appreciated. > > Here is the controller - > > def list > category_id = params[:category_id] > state_id = params[:state_id] > term_id = params[:term_id] > city = params[:city] > title = params[:title]It doesn''t look like you ever use those assignments. Are they necessary?> pq = Position.query # I''m using the plugin CriteriaQueryI''m afraid I''m not familiar with it. However...> pq.category_id_in(params[:category_id]) > unless(params[:category_id]|| "").empty?If you think it might be nil or "", you can use the blank? method.> pq.state_id_in(params[:state_id]) unless(params[:state_id]|| > "").empty? > pq.term_id_in(params[:term_id]) unless(params[:term_id]|| "").empty? > > pq.city_in(params[:city].split(",")) unless(params[:city]|| > "").empty? > pq.title_in(params[:title].split(",")) unless(params[:title]|| > "").empty? > pp pqWhat does this show you? David -- David A. Black | dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB''s Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 10/15/06, dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org <dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org> wrote:> > > Hi -- > > On Sun, 15 Oct 2006, Dark Ambient wrote: > > > Trying various things here to eliminate this problem. In my dyanmic > search , > > if no search criteria is selected then all records are returned. It''s > not > > what I want. By the way this is an observe_form. Help is greatly > > appreciated. > > > > Here is the controller - > > > > def list > > category_id = params[:category_id] > > state_id = params[:state_id] > > term_id = params[:term_id] > > city = params[:city] > > title = params[:title] > > It doesn''t look like you ever use those assignments. Are they > necessary?No they do not get used, so no they are not necessary. However this is something I haven''t quite figured out yet regarding the plugin''s behaviour. Using regular AR syntax and find commands, they will recognize those assignment. For some reason I am finding CQ does not.> pq = Position.query # I''m using the plugin CriteriaQuery > > I''m afraid I''m not familiar with it. However... > > > pq.category_id_in(params[:category_id]) > > unless(params[:category_id]|| "").empty? > > If you think it might be nil or "", you can use the blank? method.I have tried blank? with no success. Down for futher explanation.> pq.state_id_in(params[:state_id]) unless(params[:state_id]|| > > "").empty? > > pq.term_id_in(params[:term_id]) unless(params[:term_id]|| > "").empty? > > > > pq.city_in(params[:city].split(",")) unless(params[:city]|| > > "").empty? > > pq.title_in(params[:title].split(",")) unless(params[:title]|| > > "").empty? > > pp pq > > What does this show you?This is the only way I could find to allow fields that were nil (user did not make selection) to be evaluated as "". A fake out in other words. Stuart David>--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Adding something at the bottom: On 10/15/06, Dark Ambient <sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On 10/15/06, dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org <dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org> wrote: > > > > > > Hi -- > > > > On Sun, 15 Oct 2006, Dark Ambient wrote: > > > > > Trying various things here to eliminate this problem. In my dyanmic > > search , > > > if no search criteria is selected then all records are returned. It''s > > not > > > what I want. By the way this is an observe_form. Help is greatly > > > appreciated. > > > > > > Here is the controller - > > > > > > def list > > > category_id = params[:category_id] > > > state_id = params[:state_id] > > > term_id = params[:term_id] > > > city = params[:city] > > > title = params[:title] > > > > It doesn''t look like you ever use those assignments. Are they > > necessary? > > > No they do not get used, so no they are not necessary. However this is > something I haven''t quite figured out yet regarding the plugin''s behaviour. > Using regular AR syntax and find commands, they will recognize those > assignment. For some reason I am finding CQ does not. > > > pq = Position.query # I''m using the plugin CriteriaQuery > > > > I''m afraid I''m not familiar with it. However... > > > > > pq.category_id_in(params[:category_id]) > > > unless(params[:category_id]|| "").empty? > > > > If you think it might be nil or "", you can use the blank? method. > > > I have tried blank? with no success. Down for futher explanation. > > > pq.state_id_in(params[:state_id]) unless(params[:state_id]|| > > > "").empty? > > > pq.term_id_in(params[:term_id]) unless(params[:term_id]|| > > "").empty? > > > > > > pq.city_in(params[:city].split(",")) unless(params[:city]|| > > > "").empty? > > > pq.title_in(params[:title].split(",")) unless(params[:title]|| > > > "").empty? > > > pp pq > > > > What does this show you? > > > This is the only way I could find to allow fields that were nil (user did > not make selection) to be evaluated as "". > A fake out in other words. > > Stuart > > > David > > >Using PP , if for example 2 fields are selected: #<Criteria::Query:0xb5487b8 @join_aliases={"positions"=>"positions"}, @model_class=Position, @restrictions [#<Criteria::In:0xb5481a0 @attribute_name="category_id", @model_class=Position, @parent=#<Criteria::Query:0xb5487b8 ...>, @query=#<Criteria::Query:0xb5487b8 ...>, @restrictions=[], @value=["1"]>, #<Criteria::In:0xb548098 @attribute_name="state_id", @model_class=Position, @parent=#<Criteria::Query:0xb5487b8 ...>, @query=#<Criteria::Query:0xb5487b8 ...>, @restrictions=[], @value=["27"]>]> However when all fields are deselected- #<Criteria::Query:0xb43af50 @join_aliases={"positions"=>"positions"}, @model_class=Position, @restrictions=[]> Stuart -- http://en.wikipedia.org/wiki/Dark_ambient --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2006-Oct-15 12:59 UTC
Re: How to stop all records from being returned
Hi -- On Sun, 15 Oct 2006, Dark Ambient wrote:> Adding something at the bottom: > > On 10/15/06, Dark Ambient <sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> On 10/15/06, dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org <dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org> wrote: >>> >>> >>> Hi -- >>> >>> On Sun, 15 Oct 2006, Dark Ambient wrote: >>> >>>> Trying various things here to eliminate this problem. In my dyanmic >>> search , >>>> if no search criteria is selected then all records are returned. It''s >>> not >>>> what I want. By the way this is an observe_form. Help is greatly >>>> appreciated. >>>> >>>> Here is the controller - >>>> >>>> def list >>>> category_id = params[:category_id] >>>> state_id = params[:state_id] >>>> term_id = params[:term_id] >>>> city = params[:city] >>>> title = params[:title] >>> >>> It doesn''t look like you ever use those assignments. Are they >>> necessary? >> >> >> No they do not get used, so no they are not necessary. However this is >> something I haven''t quite figured out yet regarding the plugin''s behaviour. >> Using regular AR syntax and find commands, they will recognize those >> assignment. For some reason I am finding CQ does not.I''m afraid I''m not following. It''s not up to CQ to recognize the assignments; it''s up to Ruby.>>> pq = Position.query # I''m using the plugin CriteriaQuery >>> >>> I''m afraid I''m not familiar with it. However... >>> >>>> pq.category_id_in(params[:category_id]) >>>> unless(params[:category_id]|| "").empty? >>> >>> If you think it might be nil or "", you can use the blank? method. >> >> >> I have tried blank? with no success. Down for futher explanation. >> >>> pq.state_id_in(params[:state_id]) unless(params[:state_id]|| >>>> "").empty? >>>> pq.term_id_in(params[:term_id]) unless(params[:term_id]|| >>> "").empty? >>>> >>>> pq.city_in(params[:city].split(",")) unless(params[:city]|| >>>> "").empty? >>>> pq.title_in(params[:title].split(",")) unless(params[:title]|| >>>> "").empty? >>>> pp pq >>> >>> What does this show you? >> >> >> This is the only way I could find to allow fields that were nil (user did >> not make selection) to be evaluated as "". >> A fake out in other words.If it''s absolutely necessary, then: params[:city].to_s.empty? is a little nicer than that || thing.> Using PP , if for example 2 fields are selected: > #<Criteria::Query:0xb5487b8 > @join_aliases={"positions"=>"positions"}, > @model_class=Position, > @restrictions> [#<Criteria::In:0xb5481a0 > @attribute_name="category_id", > @model_class=Position, > @parent=#<Criteria::Query:0xb5487b8 ...>, > @query=#<Criteria::Query:0xb5487b8 ...>, > @restrictions=[], > @value=["1"]>, > #<Criteria::In:0xb548098 > @attribute_name="state_id", > @model_class=Position, > @parent=#<Criteria::Query:0xb5487b8 ...>, > @query=#<Criteria::Query:0xb5487b8 ...>, > @restrictions=[], > @value=["27"]>]> > > However when all fields are deselected- > #<Criteria::Query:0xb43af50 > @join_aliases={"positions"=>"positions"}, > @model_class=Position, > @restrictions=[]>I don''t have time right now to study CriteriaQuery, but it seems like a lot of work to do what should be a fairly simple query. Can you just use find with :conditions? David -- David A. Black | dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB''s Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 10/15/06, dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org <dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org> wrote:> > > Hi -- > > On Sun, 15 Oct 2006, Dark Ambient wrote: > > > Adding something at the bottom: > > > > On 10/15/06, Dark Ambient <sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> > >> On 10/15/06, dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org <dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org> wrote: > >>> > >>> > >>> Hi -- > >>> > >>> On Sun, 15 Oct 2006, Dark Ambient wrote: > >>> > >>>> Trying various things here to eliminate this problem. In my dyanmic > >>> search , > >>>> if no search criteria is selected then all records are returned. It''s > >>> not > >>>> what I want. By the way this is an observe_form. Help is greatly > >>>> appreciated. > >>>> > >>>> Here is the controller - > >>>> > >>>> def list > >>>> category_id = params[:category_id] > >>>> state_id = params[:state_id] > >>>> term_id = params[:term_id] > >>>> city = params[:city] > >>>> title = params[:title] > >>> > >>> It doesn''t look like you ever use those assignments. Are they > >>> necessary? > >> > >> > >> No they do not get used, so no they are not necessary. However this is > >> something I haven''t quite figured out yet regarding the plugin''s > behaviour. > >> Using regular AR syntax and find commands, they will recognize those > >> assignment. For some reason I am finding CQ does not. > > I''m afraid I''m not following. It''s not up to CQ to recognize the > assignments; it''s up to Ruby. > > >>> pq = Position.query # I''m using the plugin CriteriaQuery > >>> > >>> I''m afraid I''m not familiar with it. However... > >>> > >>>> pq.category_id_in(params[:category_id]) > >>>> unless(params[:category_id]|| "").empty? > >>> > >>> If you think it might be nil or "", you can use the blank? method. > >> > >> > >> I have tried blank? with no success. Down for futher explanation. > >> > >>> pq.state_id_in(params[:state_id]) unless(params[:state_id]|| > >>>> "").empty? > >>>> pq.term_id_in(params[:term_id]) unless(params[:term_id]|| > >>> "").empty? > >>>> > >>>> pq.city_in(params[:city].split(",")) unless(params[:city]|| > >>>> "").empty? > >>>> pq.title_in(params[:title].split(",")) unless(params[:title]|| > >>>> "").empty? > >>>> pp pq > >>> > >>> What does this show you? > >> > >> > >> This is the only way I could find to allow fields that were nil (user > did > >> not make selection) to be evaluated as "". > >> A fake out in other words. > > If it''s absolutely necessary, then: > > params[:city].to_s.empty? > > is a little nicer than that || thing. > > > Using PP , if for example 2 fields are selected: > > #<Criteria::Query:0xb5487b8 > > @join_aliases={"positions"=>"positions"}, > > @model_class=Position, > > @restrictions> > [#<Criteria::In:0xb5481a0 > > @attribute_name="category_id", > > @model_class=Position, > > @parent=#<Criteria::Query:0xb5487b8 ...>, > > @query=#<Criteria::Query:0xb5487b8 ...>, > > @restrictions=[], > > @value=["1"]>, > > #<Criteria::In:0xb548098 > > @attribute_name="state_id", > > @model_class=Position, > > @parent=#<Criteria::Query:0xb5487b8 ...>, > > @query=#<Criteria::Query:0xb5487b8 ...>, > > @restrictions=[], > > @value=["27"]>]> > > > > However when all fields are deselected- > > #<Criteria::Query:0xb43af50 > > @join_aliases={"positions"=>"positions"}, > > @model_class=Position, > > @restrictions=[]> > > I don''t have time right now to study CriteriaQuery, but it seems like > a lot of work to do what should be a fairly simple query. Can you > just use find with :conditions? > > > DavidI could use find with :conditions, although I haven''t really read up on how I could create a dynamic query of this nature. i.e. where any / mulitple or all fields could be used. I''m sure it can be done. CQ appealed to me as it seems a simpler way to write things. I wouldn''t be the best representative of the plugin. Stuart --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Top posting, because I solved the issue with -
if
!params[:category_id]
!params[:state_id]
!params[:term_id]
!params[:city]
!params[:title]
"no criteria enetered"
else
...................................
..................................
So using the plugin Criteria Query, my code for the 5 form fields ( just
posting here to see if using just find woudl require more/less or the same
amount of code) -
pq = Position.query
pq.category_id_in(params[:category_id])
unless(params[:category_id]|| "").empty?
pq.state_id_in(params[:state_id]) unless(params[:state_id]||
"").empty?
pq.term_id_in(params[:term_id]) unless(params[:term_id]||
"").empty?
pq.city_in(params[:city].split(",")) unless(params[:city]||
"").empty?
pq.title_in(params[:title].split(",")) unless(params[:title]||
"").empty?
pp pq
if
!params[:category_id]
!params[:state_id]
!params[:term_id]
!params[:city]
!params[:title]
"no criteria enetered"
else
@positions = pq.find
render :partial => "positions_list", :layout => false
-----------------
Stuart
On 10/15/06, Dark Ambient
<sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> On 10/15/06, dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
<dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org> wrote:
>
> >
> > Hi --
> >
> > On Sun, 15 Oct 2006, Dark Ambient wrote:
> >
> > > Adding something at the bottom:
> > >
> > > On 10/15/06, Dark Ambient
<sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> > >>
> > >> On 10/15/06, dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
<dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org> wrote:
> > >>>
> > >>>
> > >>> Hi --
> > >>>
> > >>> On Sun, 15 Oct 2006, Dark Ambient wrote:
> > >>>
> > >>>> Trying various things here to eliminate this problem.
In my dyanmic
> > >>> search ,
> > >>>> if no search criteria is selected then all records
are returned.
> > It''s
> > >>> not
> > >>>> what I want. By the way this is an observe_form.
Help is greatly
> > >>>> appreciated.
> > >>>>
> > >>>> Here is the controller -
> > >>>>
> > >>>> def list
> > >>>> category_id = params[:category_id]
> > >>>> state_id = params[:state_id]
> > >>>> term_id = params[:term_id]
> > >>>> city = params[:city]
> > >>>> title = params[:title]
> > >>>
> > >>> It doesn''t look like you ever use those
assignments. Are they
> > >>> necessary?
> > >>
> > >>
> > >> No they do not get used, so no they are not necessary.
However this
> > is
> > >> something I haven''t quite figured out yet regarding
the plugin''s
> > behaviour.
> > >> Using regular AR syntax and find commands, they will
recognize those
> > >> assignment. For some reason I am finding CQ does not.
> >
> > I''m afraid I''m not following. It''s not up
to CQ to recognize the
> > assignments; it''s up to Ruby.
> >
> > >>> pq = Position.query # I''m using the
plugin CriteriaQuery
> > >>>
> > >>> I''m afraid I''m not familiar with it.
However...
> > >>>
> > >>>> pq.category_id_in(params[:category_id])
> > >>>> unless(params[:category_id]|| "").empty?
> > >>>
> > >>> If you think it might be nil or "", you can use
the blank? method.
> > >>
> > >>
> > >> I have tried blank? with no success. Down for futher
explanation.
> > >>
> > >>> pq.state_id_in(params[:state_id])
unless(params[:state_id]||
> > >>>> "").empty?
> > >>>> pq.term_id_in(params[:term_id])
unless(params[:term_id]||
> > >>> "").empty?
> > >>>>
> > >>>> pq.city_in(params[:city].split(","))
unless(params[:city]||
> > >>>> "").empty?
> > >>>>
pq.title_in(params[:title].split(","))
> > unless(params[:title]||
> > >>>> "").empty?
> > >>>> pp pq
> > >>>
> > >>> What does this show you?
> > >>
> > >>
> > >> This is the only way I could find to allow fields that were
nil (user
> > did
> > >> not make selection) to be evaluated as "".
> > >> A fake out in other words.
> >
> > If it''s absolutely necessary, then:
> >
> > params[:city].to_s.empty?
> >
> > is a little nicer than that || thing.
> >
> > > Using PP , if for example 2 fields are selected:
> > > #<Criteria::Query:0xb5487b8
> > > @join_aliases={"positions"=>"positions"},
> > > @model_class=Position,
> > > @restrictions> > > [#<Criteria::In:0xb5481a0
> > > @attribute_name="category_id",
> > > @model_class=Position,
> > > @parent=#<Criteria::Query:0xb5487b8 ...>,
> > > @query=#<Criteria::Query:0xb5487b8 ...>,
> > > @restrictions=[],
> > > @value=["1"]>,
> > > #<Criteria::In:0xb548098
> > > @attribute_name="state_id",
> > > @model_class=Position,
> > > @parent=#<Criteria::Query:0xb5487b8 ...>,
> > > @query=#<Criteria::Query:0xb5487b8 ...>,
> > > @restrictions=[],
> > > @value=["27"]>]>
> > >
> > > However when all fields are deselected-
> > > #<Criteria::Query:0xb43af50
> > > @join_aliases={"positions"=>"positions"},
> > > @model_class=Position,
> > > @restrictions=[]>
> >
> > I don''t have time right now to study CriteriaQuery, but it
seems like
> > a lot of work to do what should be a fairly simple query. Can you
> > just use find with :conditions?
> >
> >
> > David
>
>
> I could use find with :conditions, although I haven''t really read
up on
> how I could create a dynamic query of this nature.
> i.e. where any / mulitple or all fields could be used. I''m sure
it can be
> done. CQ appealed to me as it seems a simpler way to write things. I
> wouldn''t be the best representative of the plugin.
>
> Stuart
>
>
--
http://en.wikipedia.org/wiki/Dark_ambient
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---