You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What were you trying to do?
I was trying to add role to User model as enum field
What did you end up with (logs, or, even better, example apps are great!)?
This is my migration for creating user roles
classAddRoleToUser < ActiveRecord::Migration[7.1]defupcreate_enum:user_roles,%w[adminuser]add_column:users,:role,:enum,enum_type: :user_roles,default: 'user',null: falseenddefdownremove_column:users,:roleexecute<<-SQL DROP TYPE user_roles; SQLendend
this is what was generated after running rails generate administrate:install non-necessary info omitted.
classUserDashboard < Administrate::BaseDashboard# ATTRIBUTE_TYPES# a hash that describes the type of each of the model's fields.## Each different type represents an Administrate::Field object,# which determines how the attribute is displayed# on pages throughout the dashboard.ATTRIBUTE_TYPES={id: Field::Number,# ...role: Field::Select.with_options(searchable: false,collection: lambda{ |field|
field.resource.class.send(field.attribute.to_s.pluralize).keys}),# ...}.freeze
This is what I have received after running this auto-generated code. I believe this is error-phone.
I could fix it with adding the following lines to rails model.
defself.roles{admin: :admin,user: :user}end
I believe we should follow the principle of least surprise. Error message should contain info that you ought to define ROLES constant or define class method roles, but it should be verbose and easy to understand. I think it can be improved and I can handle fix, thank you for the great gem 😃
What versions are you running?
Rails 7.1.2
administrate 0.19.0
The text was updated successfully, but these errors were encountered:
What were you trying to do?
I was trying to add role to User model as enum field
What did you end up with (logs, or, even better, example apps are great!)?
This is my migration for creating user roles
this is what was generated after running
rails generate administrate:install
non-necessary info omitted.This is what I have received after running this auto-generated code. I believe this is error-phone.
I could fix it with adding the following lines to rails model.
I believe we should follow the principle of least surprise. Error message should contain info that you ought to define
ROLES
constant or define class methodroles
, but it should be verbose and easy to understand. I think it can be improved and I can handle fix, thank you for the great gem 😃The text was updated successfully, but these errors were encountered: