在ActiveAdmin索引视图列中显示子属性/嵌套属性 [英] Show child/nested attributes in ActiveAdmin index view column
本文介绍了在ActiveAdmin索引视图列中显示子属性/嵌套属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在ActiveAdmin中显示嵌套属性的值。
I'm trying to show the value of a nested attribute in ActiveAdmin.
我的代码如下:
index do
column :code
column 'Sales Agent' do |client|
client.sales_agent.agent_name
end
end
我:
NoMethodError in Admin/client_branches#index
Showing /Users/constantlm/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.4.3/app/views/active_admin/resource/index.html.arb where line #1 raised:
undefined method `agent_name' for nil:NilClass
我不明白为什么这行不通,因为当我这样做时以下内容:
I don't understand why this doesn't work, because when I do the following:
index do
column :code
column 'Sales Agent' do |client|
raise client.sales_agent.agent_name.inspect
end
end
输出:
RuntimeError in Admin/client_branches#index
Showing /Users/constantlm/.rvm/gems/ruby-1.9.2-p290/gems/activeadmin-0.4.3/app/views/active_admin/resource/index.html.arb where line #1 raised:
"Peter John"
我希望第一条语句也能做到这一点(指彼得·约翰),但事实并非如此。我缺少什么?
Which is what I would expect the first statement to do as well (referring to the "Peter John"), but it's not. What am I missing?
推荐答案
清除记录并从新记录开始。另外,如果!client.sales_agent.nil是否尝试添加
Clear your records and start with new records. Additionally try adding
client.sales_agent.agent_name if !client.sales_agent.nil?
这篇关于在ActiveAdmin索引视图列中显示子属性/嵌套属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文