Search code examples
ruby-on-railsruby-on-rails-4rails-admin

filter export result by email in rails admin


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?


Solution

  • 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 }