Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Column separator is ignored when exporting #2740

Closed
loicginoux opened this issue Oct 13, 2016 · 1 comment
Closed

Column separator is ignored when exporting #2740

loicginoux opened this issue Oct 13, 2016 · 1 comment

Comments

@loicginoux
Copy link
Contributor

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.

@mshibuya
Copy link
Member

Fixed by #2741.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants