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

Enum fields should be generated as Field::Select instead of Field::String #1629

Closed
betelgeuse opened this issue Apr 29, 2020 · 1 comment · Fixed by #1655
Closed

Enum fields should be generated as Field::Select instead of Field::String #1629

betelgeuse opened this issue Apr 29, 2020 · 1 comment · Fixed by #1655
Labels
bug breakages in functionality that is implemented fields new fields, displaying and editing data

Comments

@betelgeuse
Copy link
Contributor

  • What were you trying to do?
    Run generator for a ActiveRecord model with an enum column.
  • What did you end up with (logs, or, even better, example apps are great!)?
    Dashboard with Field::String
  • What versions are you running?
    • Rails: 6.0
    • administrate: master

The generated field should be like this

enum_attribute: Field::Select.with_options(collection: Model.enum_attributes.keys)

With Field::String submitting to the update action with invalid value results in a Server Error of ArgumentError in Admin::ModelController#update

@betelgeuse betelgeuse added the bug breakages in functionality that is implemented label Apr 29, 2020
@betelgeuse betelgeuse changed the title enum fields should be generated as Field::Select instead of Field::String Enum fields should be generated as Field::Select instead of Field::String Apr 29, 2020
@nickcharlton nickcharlton added the fields new fields, displaying and editing data label Apr 30, 2020
@pablobm
Copy link
Collaborator

pablobm commented May 1, 2020

This might be a matter of changing this mapping:

module Administrate
module Generators
class DashboardGenerator < Rails::Generators::NamedBase
ATTRIBUTE_TYPE_MAPPING = {
boolean: "Field::Boolean",
date: "Field::Date",
datetime: "Field::DateTime",
enum: "Field::String",
float: "Field::Number",
integer: "Field::Number",
time: "Field::Time",
text: "Field::Text",
string: "Field::String",
}

Not 100% sure though. @betelgeuse, do you think you could try a PR?

pablobm pushed a commit that referenced this issue Jun 2, 2020
* Fixes #1629

* Define enum collection option as a proc

* make proc regexp better

Co-authored-by: Tadeusz Niemiec <tadeusz@applover.pl>
KingTiger001 added a commit to KingTiger001/admin-Rails-project that referenced this issue Jan 15, 2023
* Fixes thoughtbot/administrate#1629

* Define enum collection option as a proc

* make proc regexp better

Co-authored-by: Tadeusz Niemiec <tadeusz@applover.pl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug breakages in functionality that is implemented fields new fields, displaying and editing data
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants