-
Notifications
You must be signed in to change notification settings - Fork 21
Fixes #18: by including a reference to a collections parent_id if pre… #19
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
base: master
Are you sure you want to change the base?
Changes from all commits
8835f9e
3e0d6c3
fcde770
6dc017f
3ba7419
223f32a
f37d7dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,12 +31,13 @@ def csv_importable(options = {}) | |
| collection_action :import_csv do | ||
| @columns = columns | ||
| @required_columns = required_columns | ||
| @collection_path = parent ? collection_path({"#{parent.class.name.underscore}_id" => parent.id}) : collection_path | ||
|
|
||
| @post_path = options[:path].try(:call) | ||
| @post_path ||= collection_path + '/import_rows' | ||
| @post_path ||= @collection_path + '/import_rows' | ||
|
|
||
| @redirect_path = options[:redirect_path].try(:call) | ||
| @redirect_path ||= collection_path | ||
| @redirect_path ||= @collection_path | ||
|
|
||
| @delimiter = options[:delimiter] | ||
|
|
||
|
|
@@ -53,7 +54,7 @@ def csv_importable(options = {}) | |
| row_number = row_params.delete('_row') | ||
|
|
||
| resource = existing_row_resource(options[:import_unique_key], row_params) | ||
| resource ||= active_admin_config.resource_class.new | ||
| resource ||= build_row_resource | ||
|
|
||
| unless update_row_resource(resource, row_params) | ||
| @failures << { | ||
|
|
@@ -87,6 +88,12 @@ def update_row_resource(resource, params) | |
| resource.save | ||
| end | ||
|
|
||
| def build_row_resource | ||
| resource = end_of_association_chain.new | ||
| # controller before create callback | ||
| resource = before_create(resource) if respond_to? :before_create | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels a bit odd. Should at least be namespaced to CSV. Was this something here already?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yea, good point namespacing. It's a new addition, it felt right to put the build logic into it's own method but it's something we could of easily had left in the |
||
| end | ||
|
|
||
| def existing_row_resource(lookup_column, params) | ||
| return unless lookup_column | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does
buildwork here instead ofnew? Might be a bit more idiomatic.