简体   繁体   中英

How to map id to name in active admin index?

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?

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

You can do it lik this too

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM