问题
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