Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActiveAdmin Filters For UUID #4380

Closed
dheerajk3 opened this issue Apr 4, 2016 · 3 comments
Closed

ActiveAdmin Filters For UUID #4380

dheerajk3 opened this issue Apr 4, 2016 · 3 comments

Comments

@dheerajk3
Copy link

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

@seanlinsley
Copy link
Contributor

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

@dheerajk3
Copy link
Author

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

@wrburgess
Copy link

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants