Rails admin - 在导出部分自定义关联的差异值
Rails admin - customize difference values of an association in Export section
我有两个模型。 JobPosition 和 LineManager 。一个直线经理可以有不同的职位,一个职位有一个直线经理。在 rails admin 中,我想导出代表直线经理属性的不同列,包括:名称、部门等!
config.model 'JobPosition' do
export do
field :line_manager, :string do
export_value do
value.name if value #value is an instance of Teacher
end
end
field :line_manager, :string do
export_value do
value.title if value #value is an instance of Teacher
end
end
field :line_manager, :string do
export_value do
value.department if value #value is an instance of Teacher
end
end
field :line_manager, :string do
export_value do
value.description if value #value is an instance of Teacher
end
end
field :line_manager, :string do
export_value do
value.job_level if value #value is an instance of Teacher
end
end
end
end
但它只应用第一个而不应用其他的。我还想更改 header 列。我尝试添加这样的标签:
field :line_manager, :string do
export_value do
lable "line manager name"
value.name if value #value is an instance of Teacher
end
end
但我想这是不正确的。你有什么想法吗?
试试 formatted_value
config.model 'JobPosition' do
configure :line_manager, :string do
formatted_value do
value.job_level if value #value is an instance of Teacher
end
end
end
一个可能的解决方案是像这个例子一样导出虚拟字段
field :line_manager_departmant, :string do
label "Line Manager Department"
pretty_value do
bindings[:object].line_manager.department
end
end
field :line_manager_description, :string do
label "Line Manager Description"
pretty_value do
bindings[:object].line_manager.description
end
end
我有两个模型。 JobPosition 和 LineManager 。一个直线经理可以有不同的职位,一个职位有一个直线经理。在 rails admin 中,我想导出代表直线经理属性的不同列,包括:名称、部门等!
config.model 'JobPosition' do
export do
field :line_manager, :string do
export_value do
value.name if value #value is an instance of Teacher
end
end
field :line_manager, :string do
export_value do
value.title if value #value is an instance of Teacher
end
end
field :line_manager, :string do
export_value do
value.department if value #value is an instance of Teacher
end
end
field :line_manager, :string do
export_value do
value.description if value #value is an instance of Teacher
end
end
field :line_manager, :string do
export_value do
value.job_level if value #value is an instance of Teacher
end
end
end
end
但它只应用第一个而不应用其他的。我还想更改 header 列。我尝试添加这样的标签:
field :line_manager, :string do
export_value do
lable "line manager name"
value.name if value #value is an instance of Teacher
end
end
但我想这是不正确的。你有什么想法吗?
试试 formatted_value
config.model 'JobPosition' do
configure :line_manager, :string do
formatted_value do
value.job_level if value #value is an instance of Teacher
end
end
end
一个可能的解决方案是像这个例子一样导出虚拟字段
field :line_manager_departmant, :string do
label "Line Manager Department"
pretty_value do
bindings[:object].line_manager.department
end
end
field :line_manager_description, :string do
label "Line Manager Description"
pretty_value do
bindings[:object].line_manager.description
end
end