Rails 5.2
datatables
我正在关注一个关于使用 Rails 实现数据表的迷你教程。桌子
class BlogDatatable < AjaxDatatablesRails::ActiveRecord
def view_columns
@view_columns ||= {
id: { source: "Blog.id" },
user: { source: "Blog.user_id"}
title: { source: "Blog.title" },
}
end
def data
records.map do |record|
{
id: record.id,
title: record.title,
DT_RowId: record.id,
}
end
end
def get_raw_records
Blog.all
end
end
我真正想为用户列显示的是用户电子邮件,但用户电子邮件在用户表中。如何使用数据表实现这一点,并且仍然能够根据电子邮件而不是 blogs 表中的 user_id 进行排序?