在rails admin中通过电子邮件过滤导出结果 [英] filter export result by email in rails admin

查看:84
本文介绍了在rails admin中通过电子邮件过滤导出结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试过滤要在 rails admin 将生成的 csv 文件中导出的数据,但我只想导出特定电子邮件的数据,以便其他用户无法导出其他人的数据.

I am trying to filter the the data to be exported in the csv file that rails admin will generate but I want to only export data for a particular email so that no other users can export another person's data.

有没有办法做到这一点?

Is there a way to do this?

推荐答案

您必须实现自己的导出操作才能执行此操作.我不会那么难,因为你可以复制粘贴现有的https://github.com/sferik/rails_admin/blob/master/lib/rails_admin/config/actions/export.rb

You will have to implement your own export action to do this. I won't be that hard since you can just copy paste the existing one found in https://github.com/sferik/rails_admin/blob/master/lib/rails_admin/config/actions/export.rb

在你自己的项目根目录中创建文件

In your own project root create the file

/lib/rails_admin/config/actions/export.rb

从那里您可以使用 current_user 变量,您可以像这样确定对象的范围:

From there you have the current_user variable available and you can scope the objects like so:

@objects = list_entries(@model_config, :export).select { |object| object.user_id == current_user.id }

这篇关于在rails admin中通过电子邮件过滤导出结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆