Administrate: Document how you could use enum's in a custom field.

Created on 4 Apr 2017  Â·  9Comments  Â·  Source: thoughtbot/administrate

Adding a custom field ala #533 is fine for something which is a bit of an minor usage in Rails. But we should document it for future users.

Related: #420.

documentation

Most helpful comment

If anyone is using the https://github.com/lucascaton/enumerate_it gem, we've created an Administrate plugin for it here: https://github.com/SourceLabsLLC/administrate-field-enumerate

All 9 comments

There are a couple plugins for enum fields in Administrate. Should we point people in the direction of those, or show them how to create a custom field of their own?

Yes. We should list a bunch, then demonstrate how to do it yourself.

For a roles user it's something like this

field :roles, :enum do
  enum do
    Role.all.collect {|role| [ role.name, role.id ]}
  end
end

Can you point me in the direction of the documentation. I would like to have a dropdown with a list of translated user roles as options for the user.role enum field

We don't currently have anything documented for enum fields specifically, but the main docs are here: https://administrate-prototype.herokuapp.com

If anyone is using the https://github.com/lucascaton/enumerate_it gem, we've created an Administrate plugin for it here: https://github.com/SourceLabsLLC/administrate-field-enumerate

Any chance this would make it into core?

Since I originally opened this PR, I've been thinking that a better solution is to provide basic enum support out of the box as it does seem to be a common enough use case.

In doing that, I think it'd be valuable to link to other solutions to the problem too. Like, we'd not care to provide the full extent of enumerate_it.

I'm going to close this issue, as this isn't what we'd like to do. But I'd definitely welcome a PR from someone who'd like to pick this up.

Another related issue: https://github.com/thoughtbot/administrate/issues/533

@nickcharlton - Has one done a PR to provide basic enum support? If not, I'm happy to submit one!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

migu0 picture migu0  Â·  3Comments

Reedian picture Reedian  Â·  4Comments

ghost picture ghost  Â·  4Comments

namiwang picture namiwang  Â·  4Comments

kwerle picture kwerle  Â·  4Comments