filter export result by email in rails admin

元气小坏坏 提交于 2019-12-11 10:06:40

问题


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?


回答1:


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

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 }


来源:https://stackoverflow.com/questions/48011662/filter-export-result-by-email-in-rails-admin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!