Last active
April 18, 2016 07:36
-
-
Save benshimmin/4256e36cd0876fa6ee1627dc74b57fc2 to your computer and use it in GitHub Desktop.
Enums with Rails Admin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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