Follow Along as I Stumble on the Path to Learning RoR

ActiveAdmin: Turning Hashes/ActiveRecord Hashes to Field Values

After I installed ActiveAdmin gem, everything worked great except I had an issue where the dropdown menus were showing ActiveRecord hashes like this:

#<Category:0x698a648>

Instead of showing a name like the other fields.  It seems that the default is to show a field called “name” in the dropdown menus in ActiveAdmin, and if you don’t have such a field it shows the ActiveRecord instead.  Changing that was easy, after I found this StackOverflow question.

All you have to do is go into the model and add a method for to_s, like this:

def to_s
# field name you want to show in the drop down
end

for me, I put:

def to_s
id
end

Advertisements

Comments are closed.