Skip to content

Parent resource is made accesible through the template object when th… #137

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ricardojudo
Copy link
Contributor

…e active admin page has the 'belongs_to' statement.

I needed to implement this change in order to get a reference of the parent resource within a proc passed to the before_batch_import option in order to insert additional information to each line.

before_batch_import: Proc.new{|importer|         
      _form = importer.model.parent
       importer.csv_lines.each do |line|
         line.push _form.id
         line.push _form.generate_registration_code
       end
 }

I was not sure where and how to document this change.

What do you think about this proposal?

…e active admin page has the 'belongs_to' statement.
@@ -76,7 +76,9 @@ def active_admin_import(options = {}, &block)
_params = params.respond_to?(:to_unsafe_h) ? params.to_unsafe_h : params
params = ActiveSupport::HashWithIndifferentAccess.new _params
@active_admin_import_model = options[:template_object]
@active_admin_import_model.assign_attributes(params[params_key].try(:deep_symbolize_keys) || {})
@active_admin_import_model.assign_attributes(params[params_key].try(:deep_symbolize_keys) || {})
@active_admin_import_model.assign_attributes(parent: parent) unless defined?(parent).nil?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [97/80]

@@ -76,7 +76,9 @@ def active_admin_import(options = {}, &block)
_params = params.respond_to?(:to_unsafe_h) ? params.to_unsafe_h : params
params = ActiveSupport::HashWithIndifferentAccess.new _params
@active_admin_import_model = options[:template_object]
@active_admin_import_model.assign_attributes(params[params_key].try(:deep_symbolize_keys) || {})
@active_admin_import_model.assign_attributes(params[params_key].try(:deep_symbolize_keys) || {})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [112/80]
Trailing whitespace detected.

@coveralls
Copy link

coveralls commented Apr 12, 2017

Coverage Status

Coverage decreased (-0.8%) to 96.942% when pulling 7afc6e6 on ricardojudo:master into 30b6d71 on activeadmin-plugins:master.

@Fivell
Copy link
Member

Fivell commented Apr 18, 2017

@ricardojudo , for new features to merge there is a requirement to add spec here https://github.com/activeadmin-plugins/active_admin_import/blob/master/spec/import_spec.rb

@@ -76,7 +76,9 @@ def active_admin_import(options = {}, &block)
_params = params.respond_to?(:to_unsafe_h) ? params.to_unsafe_h : params
params = ActiveSupport::HashWithIndifferentAccess.new _params
@active_admin_import_model = options[:template_object]
@active_admin_import_model.assign_attributes(params[params_key].try(:deep_symbolize_keys) || {})
@active_admin_import_model.assign_attributes(params[params_key].try(:deep_symbolize_keys) || {})
@active_admin_import_model.assign_attributes(parent: parent) unless defined?(parent).nil?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ricardojudo , why not
if parent? instead of defined?(parent).nil?

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

Successfully merging this pull request may close these issues.

4 participants