How to map id to name in active admin index?

我只是一个虾纸丫 提交于 2019-12-24 12:35:13

问题


I am using active admin. I have project and user model with many to many relationship between them. In my user model i have a project_leader boolean column. And in my project model i have project_leader as integer column. I am allowed to select 1 project leader for each project. And then id of the user who is the project leader is stored in Project project_leader column. How do i map the id of the user to its name from active admin index?


回答1:


Solved:

In my project model i defined a method as following.

def get_associated_user  
  p = self.project_leader  
  user = User.find(p).full_name  
end  

And from the active_admin index i just called the method object.get_associated_user




回答2:


You can do it lik this too

 column "Project Leader" do |p|
   user = User.find(p.project_leader).full_name
 end


来源:https://stackoverflow.com/questions/15832022/how-to-map-id-to-name-in-active-admin-index

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!