You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I have a standard Devise User model, for which I want to provide a bulk upload feature.
I also have rolify integrated and so as people register on the site, I give options for them to either register as a student or a teacher.
What I want to do, is use active_admin_import to provide a bulk upload feature for teachers only. So basically after the import is done, i need to assign them to teacher role.
In a normal scenario, this is done by new_user.add_role(:teacher), assuming new_user is a newly created user object.
I am not able to figure out how to get access to the instance of the created object after insertion so that I can accomplish the same.
ActiveAdmin.register User do
active_admin_import validate:false,
after_batch_import: proc { |import|
**<not sure what to put here>**
},
before_batch_import: proc { |import|
import.csv_lines.length.times do |i|
import.csv_lines[i][2] = User.new(password: import.csv_lines[i][2]).encrypted_password
end
},
template_object: ActiveAdminImport::Model.new(
hint: "file will be imported with such header format: 'full_name',''email','password'. They will assigned as teachers"
),
timestamps: true,
batch_size: 1000
index do
selectable_column
column :full_name
column :email
column :phone_number
column :roles do |user|
user.roles.collect {|c| c.name.capitalize }.to_sentence
end
column :current_sign_in_at
column :last_sign_in_at
column :created_at
end
end
Is my use of after_batch_import correct or should I go for after_import and in each case, how do i get access to the instance of the newly imported object or the array of objects imported so that I can assign the role.
Any help is appreciated
Thank you
The text was updated successfully, but these errors were encountered:
Hi,
I have a standard Devise User model, for which I want to provide a bulk upload feature.
I also have rolify integrated and so as people register on the site, I give options for them to either register as a
student
or ateacher
.What I want to do, is use active_admin_import to provide a bulk upload feature for teachers only. So basically after the import is done, i need to assign them to
teacher
role.In a normal scenario, this is done by
new_user.add_role(:teacher)
, assumingnew_user
is a newly created user object.I am not able to figure out how to get access to the instance of the created object after insertion so that I can accomplish the same.
Is my use of
after_batch_import
correct or should I go forafter_import
and in each case, how do i get access to the instance of the newly imported object or the array of objects imported so that I can assign the role.Any help is appreciated
Thank you
The text was updated successfully, but these errors were encountered: