-
Notifications
You must be signed in to change notification settings - Fork 102
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
[Idea] Add ability to provide csv template #111
Comments
@sharshenov , what are you trying to achieve with csv_template ? How it can help? |
I think it is a good idea: a template of column names could be added which would allow
A much larger feature would be the ability to specify types (or map them to actual table columns) and reject the row or whole file on a mismatch. |
@seanfcarroll , any ideas with dsl example for this new feature ? |
@sharshenov , latest release has one of features you've requested. Skip CSV-columns. Basically it allows you to specify what columns to take from CSV-file. Take a look, and share your thoughts about this implementation. Is it enough for your needs? |
+1 I monkey-patched my temporary* solution as: collection_action :template, method: :get do
respond_to do |format|
csv_template = CSV.generate do |csv|
csv << resource_class.column_names - %w[created_at updated_at].map do |attr|
resource_class.human_attribute_name(attr, default: attr.to_s.titleize)
end
end
format.csv do
send_data csv_template,
filename: "#{resource_class}_template.csv",
type: 'application/csv',
disposition: 'inline'
end
end
end
action_item :import, only: :index, if: options[:if] do
if authorized?(ActiveAdminImport::Auth::IMPORT, active_admin_config.resource_class)
span do
link_to(
I18n.t('active_admin_import.import_model', plural_model: options[:plural_resource_label]),
action: :import
)
end
span do
link_to(
I18n.t('active_admin_import.template'),
action: :template,
format: :csv
)
end
end
end
|
Just got an idea - put a link to template csv file in the upload form. Default attribute set can be taken from model (
resource.resource_class.attribute_names - ["created_at", "updated_at"]
).And provide options to configure attribute set:
The text was updated successfully, but these errors were encountered: