My application uses Rails, Activeadmin and Ransack.
Recently I've noticed that the date filtering is not working correctly. I've also checked on controllers separate from Activeadmin and the problem still persists. Could it be a Ransack problem?
The logs indicate that the params are being correctly passed through, and they are also still in the URL.. The count works fine, but the actual querying does not take place. Any ideas what could be going on here? I did recently upgrade to Ruby 2.2
but I'm not sure if that's related.
Here are the params:
Started GET "/admin/users?utf8=%E2%9C%93&q%5Bcreated_at_gteq%5D=2015-11-01&q%5Bcreated_at_lteq%5D=2015-11-30&q%5Brole_contains%5D=read&commit=Filter&order=id_desc" for 50.17.182.190 at 2015-11-13 05:16:52
+0000
Here you can see the date is never used in the SQL query:
User Load (0.8ms) SELECT "users".* FROM "users" WHERE ("users"."role" ILIKE '%read%') ORDER BY "users"."id" desc LIMIT 30 OFFSET 0
Full logs are below:
Started GET "/admin/users?utf8=%E2%9C%93&q%5Bcreated_at_gteq%5D=2015-11-01&q%5Bcreated_at_lteq%5D=2015-11-30&q%5Brole_contains%5D=read&commit=Filter&order=id_desc" for 50.17.182.190 at 2015-11-13 05:16:52
+0000
Processing by Admin::UsersController#index as HTML
Parameters: {"utf8"=>"✓", "q"=>{"created_at_gteq"=>"2015-11-01", "created_at_lteq"=>"2015-11-30", "role_contains"=>"read"}, "commit"=>"Filter", "order"=>"id_desc"}
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1
(0.4ms) SELECT COUNT(*) FROM "users" WHERE ("users"."role" ILIKE '%read%')
(0.3ms) SELECT COUNT(*) FROM "users" WHERE ("users"."role" ILIKE '%read%') AND (created_at > '2015-11-01 00:00:00.000000')
(0.3ms) SELECT COUNT(*) FROM "users" WHERE ("users"."role" ILIKE '%read%') AND (created_at > '2015-11-09 00:00:00.000000')
(0.3ms) SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM "users" WHERE ("users"."role" ILIKE '%read%') LIMIT 30 OFFSET 0) subquery_for_count
CACHE (0.0ms) SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM "users" WHERE ("users"."role" ILIKE '%read%') LIMIT 30 OFFSET 0) subquery_for_count
CACHE (0.0ms) SELECT COUNT(*) FROM "users" WHERE ("users"."role" ILIKE '%read%')
CACHE (0.0ms) SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM "users" WHERE ("users"."role" ILIKE '%read%') LIMIT 30 OFFSET 0) subquery_for_count
User Load (0.8ms) SELECT "users".* FROM "users" WHERE ("users"."role" ILIKE '%read%') ORDER BY "users"."id" desc LIMIT 30 OFFSET 0
I just had a problem like this. It turns out that I was submitting the date in american format (mm-dd-yyyy
) but the server was interpreting it as yyyy-mm-dd
or dd-mm-yyy
, which causes your date to fail silently and return nil once rails/ruby processes it. I installed the american_date
gem and it fixed it.
Ruby internally (in the Date
and DateTime
classes) used to process american dates just fine, but the community has decided (probably rightly) that american-style dates aren't a good default for international users. So that's probably why you noticed this after upgrading ruby.