Skip to content

Commit 80354a6

Browse files
author
James McKinney
committed
Merge pull request activeadmin#1608 from railscard/default-csv-separator
Added config option to set default CSV builder separator
2 parents 2d6a55d + 0293fef commit 80354a6

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

app/views/active_admin/resource/index.csv.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
CSV
88
end
99

10-
csv_output = csv_lib.generate(:col_sep => active_admin_config.csv_builder.column_separator || ',') do |csv|
10+
csv_output = csv_lib.generate(:col_sep => active_admin_config.csv_builder.column_separator || active_admin_application.csv_column_separator) do |csv|
1111
columns = active_admin_config.csv_builder.columns
1212
csv << columns.map(&:name)
1313
collection.each do |resource|

features/index/format_as_csv.feature

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,21 @@ Feature: Format as CSV
6161
| Title | Body |
6262
| Hello, World | (.*) |
6363

64+
Scenario: With default CSV separator option
65+
Given a configuration of:
66+
"""
67+
ActiveAdmin.application.csv_column_separator = ';'
68+
ActiveAdmin.register Post do
69+
csv do
70+
column :title
71+
column :body
72+
end
73+
end
74+
"""
75+
And a post with the title "Hello, World" exists
76+
When I am on the index page for posts
77+
And I follow "CSV"
78+
And I should download a CSV file with ";" separator for "posts" containing:
79+
| Title | Body |
80+
| Hello, World | (.*) |
81+

lib/active_admin/application.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ def self.inheritable_setting(name, default)
6666
# The namespace root.
6767
inheritable_setting :root_to, 'dashboard#index'
6868

69+
# Default CSV separator
70+
inheritable_setting :csv_column_separator, ','
71+
6972
# Active Admin makes educated guesses when displaying objects, this is
7073
# the list of methods it tries calling in order
7174
setting :display_name_methods, [ :display_name,

lib/generators/active_admin/install/templates/active_admin.rb.erb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,10 @@ ActiveAdmin.setup do |config|
140140
#
141141
# To load a javascript file:
142142
# config.register_javascript 'my_javascript.js'
143+
144+
145+
# == CSV options
146+
#
147+
# Set the CSV builder separator (default is ",")
148+
# config.csv_column_separator = ','
143149
end

0 commit comments

Comments
 (0)