Search code examples
ruby-on-railsrubyexportrails-admin

How to hide Rails Admin CSV options while exporting


I have a Ruby on Rails app and am using I'm using Rails Admin. I want to hide the export options such as Encode to, No header and Column separator. Is this possible?

I've tried this but surely it's wrong:

config.actions do
  dashboard                    
  end    
  index                        
  new 
  export do
    options ['encode']
  end
  # show_in_app
  ## With an audit adapter, you can add:
  # history_index
  # history_show
end

Solution

  • Navigate to rails admin github page and download the views folder. Copy this file /rails_admin/main/export.html.haml in the same directory of your project.If you don't have the directory create one. Then comment these lines :

      / %fieldset
      /   %legend
      /     %i.icon-chevron-down
      /     = t('admin.export.options_for', name: 'csv')
      /   .form-group.control-group
      /     - guessed_encoding = @abstract_model.encoding
      /     %label.col-sm-2.control-label{for: "csv_options_encoding_to"}= t('admin.export.csv.encoding_to')
      /     .col-sm-10.controls
      /       -# from http://books.google.com/support/partner/bin/answer.py?answer=30990 :
      /       = select_tag 'csv_options[encoding_to]', options_for_select(Encoding.name_list.sort), include_blank: true, placeholder: t('admin.misc.search'), :'data-enumeration' => true
      /       %p.help-block= t('admin.export.csv.encoding_to_help', name: guessed_encoding)
    
      /   .form-group.control-group
      /     %label.col-sm-2.control-label{for: "csv_options_skip_header"}= t('admin.export.csv.skip_header')
      /     .col-sm-10.controls
      /       .checkbox
      /         %label{style: 'display: block;' }
      /           = check_box_tag 'csv_options[skip_header]', 'true'
      /       %p.help-block= t('admin.export.csv.skip_header_help')
    
      /   .form-group.control-group
      /     %label.col-sm-2.control-label{for: "csv_options_generator_col_sep"}= t('admin.export.csv.col_sep')
      /     .col-sm-10.controls
      /       = select_tag 'csv_options[generator][col_sep]', options_for_select({ '' => t('admin.export.csv.default_col_sep'), "<comma> ','" => ',', "<semicolon> ';'" => ';', '<tabs>' => "'\t'" }), placeholder: t('admin.misc.search'), :'data-enumeration' => true
      /       %p.help-block= t('admin.export.csv.col_sep_help', value: t('admin.export.csv.default_col_sep'))
    

    Now The export options will be removed!