我有一个 Rails 应用程序,其中用户有一个性别,这是一个枚举,其中 0 表示女性,1 表示男性。
我在 user_dashboard.rb 中有这段代码:
require "administrate/base_dashboard"
class UserDashboard < Administrate::BaseDashboard
ATTRIBUTE_TYPES = {
posts: Field::HasMany,
id: Field::Number.with_options(searchable: false),
email: Field::String.with_options(searchable: true),
password: Field::String.with_options(searchable: false),
password_confirmation: Field::String.with_options(searchable: false),
encrypted_password: Field::String.with_options(searchable: false),
reset_password_token: Field::String.with_options(searchable: false),
reset_password_sent_at: Field::DateTime.with_options(searchable: false),
remember_created_at: Field::DateTime.with_options(searchable: false),
first_name: Field::String.with_options(searchable: false),
last_name: Field::String.with_options(searchable: false),
gender: Field::Text.with_options(searchable: false),
type: Field::String.with_options(searchable: false),
created_at: Field::DateTime.with_options(searchable: false),
updated_at: Field::DateTime.with_options(searchable: false),
phone: Field::String.with_options(searchable: false),
}.freeze
COLLECTION_ATTRIBUTES = %i[
posts
email
phone
type
].freeze
SHOW_PAGE_ATTRIBUTES = %i[
posts
id
email
phone
first_name
last_name
gender
type
created_at
updated_at
].freeze
FORM_ATTRIBUTES = %i[
posts
email
phone
first_name
last_name
gender
password
password_confirmation
type
].freeze
COLLECTION_FILTERS = {}.freeze
end
只有管理员可以创建用户,但他们必须手动输入“男性”或“女性”等性别。有没有办法集成可以与管理 gem 一起使用的选择菜单或单选按钮?