Skip to content

Instantly share code, notes, and snippets.

@benshimmin
Last active April 18, 2016 07:36
Show Gist options
  • Save benshimmin/4256e36cd0876fa6ee1627dc74b57fc2 to your computer and use it in GitHub Desktop.
Save benshimmin/4256e36cd0876fa6ee1627dc74b57fc2 to your computer and use it in GitHub Desktop.
Enums with Rails Admin
# This might not be the best way, it might be improved in more
# recent versions of Rails Admin, but this seems to work okay
# for me.
class SomeModel < ActiveRecord::Base
enum :some_enum => {
:some_key => 0
}
rails_admin do
field :some_enum, :enum do
searchable false
enum do
SomeModel.some_enums.map { |k,_| [k.titleize, k] }
end
pretty_value do
if bindings[:object]
bindings[:object].send(:some_enum).titleize
end
end
def form_value
bindings[:object].some_enum
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment