我有两个模型:User
和Dog
。我希望能够在单个Datagrid报告中显示它们。使用column()
方法时,我使用什么语法来引用用户模型的特定属性?现在我只是显示User
对象,但我希望显示:name
模型的:gender
,:age
和User
属性的各个列。< / p>
class User < ActiveRecord::Base
attr_accessible :email, :age, :gender, :name
has_many :dogs
class Dog < ActiveRecord::Base
attr_accessible :name, :age
belongs_to :user
class DogReport
include Datagrid
#
# Scope
#
scope do
Dog.includes(:user)
end
#
# Filters
#
filter(:dog_id, :integer)
#
# Columns
#
column(:id)
column(:name)
column(:age)
column(:user)
end
答案 0 :(得分:0)
column(:user, :header => "user.name") do
self.user.name
end