Ruby On Rails Active Admin has_many changing dropdown to use a different column

后端 未结 2 809
不知归路
不知归路 2021-01-06 09:30

I am completely new to ActiveAdmin and RoR and i cant figure out how to change the visible value of the dropdowns in a has_many association.

Fillup Model



        
2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-06 10:12

    In your Car model, just add something like :

    def to_s
      description
    end
    

    It should do the job !

    Explanation : Actually, your Car's to_s method returns the object id corresponding to the current instance, that's the default thing used when using a method like puts on an object. To replace a model's display name, you have to override this method and it will work anywhere in your app when you use puts @car or in your templates doing <%= @car %>

提交回复
热议问题