Skip to content

Column separator is ignored when exporting #2740

@loicginoux

Description

@loicginoux

When exporting, there is an selectbox to choose which column separator to be used in the csv file generated.
This is not working and will always take the default option of the csv converter.

in lib/rails_admin/config/actions/index.rb we have:

header, encoding, output = CSVConverter.new(@objects, @schema).to_csv(params[:csv_options].permit!.to_h)

with a params[:csv_options] being for example {encoding_to: "", generator: {col_sep: ";"}}

the method .to_h transforms the keys in strings but the method .to_csv of /lib/rails_admin/support/csv_converter.rb expects to have the option with symbol keys:

def generate_csv_string(options)
      generator_options = (options[:generator] || {}).symbolize_keys.delete_if { |_, value| value.blank? }
      method = @objects.respond_to?(:find_each) ? :find_each : :each

      CSV.generate(generator_options) do |csv|

I use version rails 4.2.5. Having a look at the documentation of http://devdocs.io/rails~4.2/actioncontroller/parameters
the method to_h sends back a Hash while rails rails 5.0 sends back a HashWithIndifferentAccess (http://api.rubyonrails.org/classes/ActionController/Parameters.html#method-i-to_h) so I guess using rails 5 will fix the issue.
I guess the solution that would work on any cas would be to transform the options parameters in
CSVConverter in a HashWithIndifferentAccess.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions