-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Add native support for ActiveRecord Enums #3157
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
Comments
I can take a look on this. |
@AlexeyMK I have take a look on that and i think this should be done by Formtastic and not by AA |
makes sense. |
If someone can get a PR merged on Formtastic's side, sure, but Active Admin has plenty of custom form code. |
Formtastic has that on his feature list (formtastic/formtastic#1059) |
@justinfrench has implemented this already according to formtastic/formtastic#1098. Any news about the current status as of now or a workaround that works for edit forms? |
Here are no news. Maybe some want to work on this? |
For the record for other folks coming across this issue, the workaround is to explicitly specify the input for that column as a form do |f|
f.semantic_errors *f.object.errors.keys
f.inputs do
f.input :status, as: :select, collection: MyModel.statuses.keys
# other attribute fields...
end
f.actions
end ...where |
@thom-nic Do you know how to filter by enums fields? Thanks |
👍 @XBeg9: I found this here http://stackoverflow.com/a/25437896/784318: filter :level, as: :select, collection: Model.levels |
This solution makes the filtering functionality work, but the "Current filters" section displays the integer values, like "Current filters: Status equals 2". And unfortunately using the So, one more small thing that it would be great to have AA do automatically if possible. |
I somewhat looked into a way to implement enum keys into the filter message. It seems that a method |
Just FYI the filter problem is still actual in 2021. |
I needed MyModel.statuses.symbolize_keys to get this to work |
|
We have a PR for this. Thank you. |
This is still very much a desired feature for me. I inherited an application where a combination of Enumerize and enum are used with ActiveAdmin filter and input forms. For ActiveRecord models with:
I cannot use:
and the int is shown in the view of active filters. Alternatively, some of the models have varchar (int was used for models with enum) for their status column type in MySQL and use:
For these models, I can use:
and in the view of active filters I will see "Status in scheduled", instead of "Status in 1" that the models using enum show. This was all very confusing to me when I inherited this application and I did not find any help in documentation or online.This may be a helpful work around until the PR is merged. |
@npgretz hmm I don't know if it would work with a multi select. For enums, I use check boxes and that I know does work. filter :status, as: :check_boxes, collection: -> { MyModel.statuses } |
Rails 4.1 now has support for enums.
It seems pretty straightforward to default enum columns to a select in the edit form window: http://stackoverflow.com/questions/23414880/how-to-properly-configure-rails-4-1-enums-in-activeadmin/23799562#23799562
Would be pretty awesome to support this natively, without requiring additional customization.
The text was updated successfully, but these errors were encountered: