Revision 229195a5
Added by Tomer Brisker about 7 years ago
app/helpers/application_helper.rb | ||
---|---|---|
display_link_if_authorized(name, options, html_options)
|
||
end
|
||
|
||
def csv_link
|
||
link_to(_('Export'), params.merge(:format => :csv),
|
||
{:title => _('Export to CSV'), :class => 'btn btn-default', 'data-no-turbolink' => true})
|
||
end
|
||
|
||
# renders a style=display based on an attribute properties
|
||
def display?(attribute = true)
|
||
"style=#{display(attribute)}"
|
Also available in: Unified diff
Fixes #18760 - Allow export to CSV
This introduces a way of exporting tables from the UI to CSV.
There are 3 steps to adding a CSV export to a table:
1. Add the CsvResponder concern to the relevant controller.
2. Add a `format.csv` block to the index controller action. This block
should include a call to `csv_response` with the wanted resources.
3. Add `csv_link` to the title actions. (Or wherever you want the export
button to appear)
By default, the csv will include all columns that exist for that model
in the database, except for the `created_at` and `updated_at` ones. To
override the default, add a method `csv_columns` to the controllers that
returns an array of columns. Columns can be actual column names in the
database, reflections, or any method that can be called on an instance
of the model.
This commit also includes an example of the feature implemented on the
Hosts index page.