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 #533
Comments
enum_field.rb require "administrate/field/base"
class EnumField < Administrate::Field::Base
def to_s
data
end
def select_field_values(form_builder)
form_builder.object.class.public_send(attribute.to_s.pluralize).keys.map do |v|
[v.titleize, v]
end
end
end _form.html.erb <div class="field-unit__label">
<%= f.label field.attribute %>
</div>
<div class="field-unit__field">
<%= f.select field.attribute, field.select_field_values(f) %>
</div> (_show/_index).html.erb <%= field.to_s.titleize %> |
@hauleth Does the custom field that @stevenpetryk illustrated above work for your needs? If so, would you or he like to take a stab at creating it as a plugin? Here's an example: |
Worked for me. You might want to change EnumField#to_s to
In case the enum data is nil |
@stevenpetryk what is the benefit over Field::Select.with_options(collection: Model::ENUM) ? |
@carsonbland I'm not sure – it may very well be the case that that was undocumented/impossible back when I posted that response. If that works, then go for it! |
Closing this, since a custom enum field with |
@stevenpetryk great solution! Thanks!! |
@BenMorganIO Sounds like this should be part of core |
attempted to use an Enum field in administrate with no success so ended up using string `rails g administrate:field enum` as enum did nothing much and did not create a select box which would have been helpfull as per example in thoughtbot/administrate#533 (comment)
It would be really useful to have some way to entry values for
has_entry
.The text was updated successfully, but these errors were encountered: