Fellow Stranger
Fellow Stranger

Reputation: 34093

Find objects with a certain Enum attribute value

class User < ActiveRecord::Base
  enum role: %w(employee admin manager)
end

How can I find all users with the role "admin"?

This doesn't return any user: User.where(role: "admin")

Upvotes: 0

Views: 123

Answers (1)

Serdar Dogruyol
Serdar Dogruyol

Reputation: 5157

You can do it like

User.where(role: User.roles['admin'])

Also

User.admin

works for your case

Upvotes: 1

Related Questions