I am aware that date selects params are supposed to supported by
Searchlogic.
But I''m battling to get them working.
I am using one of the named_scopes that it makes, and it works perfectly
in the console:
User.created_at_gte(1.year.ago)
this behaves as expected.
In my view I have this:
- form_for @search do |f|
  Surname
  =f.text_field :surname_like
  Age between
  =f.text_field :age_gte
  =f.text_field :age_lte
  Joined after
  =f.date_select :created_at_gte
  =f.submit "Search"
the error I get is when actually using the field, I get this error:
The  is not a valid condition. You may only use conditions that map to a
named scope
and the params are:
{"commit"=>"Search",
 "search"=>{"created_at_gte(1i)"=>"2011",
 "created_at_gte(2i)"=>"2",
 "created_at_gte(3i)"=>"25",
 "age_gte"=>"5",
 "order"=>"",
 "surname_like"=>"",
 "age_lte"=>"25"}}
Now unless I''m wrong, searchlogic should be able to parse the params
with their date groups. Or it''s just being stupid and thinking
"created_at_gte(1i)" is a named scope. In which case I''m
going to have
to alter the params to make it friendly for searchlogic.
anythink I''m missing?
-- 
Posted via http://www.ruby-forum.com/.
-- 
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
+1, hit this nail right on today :( On Feb 25, 7:27 pm, Stuart Corbishley <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I am aware that date selects params are supposed to supported by > Searchlogic. > > But I''m battling to get them working. > > I am using one of the named_scopes that it makes, and it works perfectly > in the console: > > User.created_at_gte(1.year.ago) > > this behaves as expected. > > In my view I have this: > > - form_for @search do |f| > Surname > =f.text_field :surname_like > Age between > =f.text_field :age_gte > =f.text_field :age_lte > Joined after > =f.date_select :created_at_gte > > =f.submit "Search" > > the error I get is when actually using the field, I get this error: > The is not a valid condition. You may only use conditions that map to a > named scope > > and the params are: > > {"commit"=>"Search", > "search"=>{"created_at_gte(1i)"=>"2011", > "created_at_gte(2i)"=>"2", > "created_at_gte(3i)"=>"25", > "age_gte"=>"5", > "order"=>"", > "surname_like"=>"", > "age_lte"=>"25"}} > > Now unless I''m wrong, searchlogic should be able to parse the params > with their date groups. Or it''s just being stupid and thinking > "created_at_gte(1i)" is a named scope. In which case I''m going to have > to alter the params to make it friendly for searchlogic. > > anythink I''m missing? > -- > Posted viahttp://www.ruby-forum.com/.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
William Yeung wrote:> +1, hit this nail right on today :(Sorry for the late reply, u probably moved on from this. I got a method that takes all the date params from the params and changes them to a friendlier version. def parse_date_params(param_hash) hash = param_hash.clone regexp = /(.+)\((\d)[a-zA-Z]\)/ dates_arrays = hash.select{|key, value| key.to_s.match(regexp) } hash.delete_if{|key, value| key.to_s.match(regexp) } add_to_hash = {} dates_arrays.each do |a| matchdata = a[0].match(regexp) # check for all three. add_to_hash[matchdata[1]] ? add_to_hash[matchdata[1]][matchdata[2]] = a[1] : add_to_hash[matchdata[1]] = {matchdata[2] => a[1]} end add_to_hash.each_pair { |key, value| hash[key] = Date.civil(value["1"].to_i, value["2"].to_i,value["3"].to_i)} return hash end let me know if that helps. -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.