Activeadmin: ActiveAdmin Filters For UUID

Created on 4 Apr 2016  ·  3Comments  ·  Source: activeadmin/activeadmin

I have implemented UUID functionality on user model using the below link http://rny.io/rails/postgresql/2013/07/27/use-uuids-in-rails-4-with-postgresql.html

Now my current schema looks like this:

create_table "users", force: :cascade do |t|
t.string   "email",
t.string   "first_name"
t.string   "last_name"
t.uuid     "user_uid",   default: "uuid_generate_v4()"
end

I tried to use below two lines to add a filter on active admin user index page

filter :user_uid, as: :uuid, label: "USER UUID"
filter :user_uid, as: :string, label: "USER UUID"

But I am getting following error like below:

Started GET "/admin/users?utf8=%E2%9C%93&q%5Buser_uid_cont%5D=b216d8af-fbd5-401f-886e-3615b8f57cee&commit=Filter&order=id_desc" for 127.0.0.1 at 2016-04-04 23:08:03 +0530
Processing by Admin::UsersController#index as HTML
Parameters: {"utf8"=>"✓", "q"=>{"user_uid_cont"=>"b216d8af-fbd5-401f-886e-3615b8f57cee"}, "commit"=>"Filter", "order"=>"id_desc"}
AdminUser Load (0.3ms) SELECT "admin_users".* FROM "admin_users" WHERE "admin_users"."id" = $1 ORDER BY "admin_users"."id" ASC LIMIT 1 ["id", 1] SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM "users" WHERE ("users"."user_uid" ILIKE NULL) LIMIT 30 OFFSET 0) subquery_for_count
PG::UndefinedFunction: ERROR: operator does not exist: uuid ~~* unknown
LINE 1: ...unt_column FROM "users" WHERE ("users"."user_uid" ILIKE NULL...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
: SELECT COUNT(count_column) FROM (SELECT 1 AS count_column FROM "users" WHERE ("users"."user_uid" ILIKE NULL) LIMIT 30 OFFSET 0) subquery_for_count
Rendered /home/chetuiwk1457/.rvm/gems/ruby-2.2.3@amburcloud/bundler/gems/activeadmin-81537db36107/app/views/active_admin/resource/index.html.arb (165.8ms)
Completed 500 Internal Server Error in 176ms (ActiveRecord: 3.2ms)

Any suggestions for using ActiveAdmin filters with UUID

Most helpful comment

I ran into errors with this solution on Rails 5 and ActiveAdmin 1.0.0.pre4, but using this filter worked for me:

filter :id_eq, label: "ID"

All 3 comments

That's not surprising -- Postgres doesn't implement ILIKE for UUID data.

You can get around this by specifying that you want an equality filter instead of the default text filter:

filter :user_uid_eq

This fixed my issue, I am going to close this ticket. Thank you...!

I ran into errors with this solution on Rails 5 and ActiveAdmin 1.0.0.pre4, but using this filter worked for me:

filter :id_eq, label: "ID"

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ryanwood picture ryanwood  ·  4Comments

Nitrino picture Nitrino  ·  3Comments

thejspr picture thejspr  ·  3Comments

zhdwwf picture zhdwwf  ·  4Comments

daya picture daya  ·  3Comments