Skip to content

Instantly share code, notes, and snippets.

@JamesDullaghan
Created January 10, 2018 20:12
Show Gist options
  • Save JamesDullaghan/05dc3d068015ae4c72f5880e3a1fa228 to your computer and use it in GitHub Desktop.
Save JamesDullaghan/05dc3d068015ae4c72f5880e3a1fa228 to your computer and use it in GitHub Desktop.
Copy task list templates from one team to a group of other teams

To Only remove task templates and recreate

# find source team
src_team = Team.find 836
# find each org
iserve = Organization.find 575
idirect = Organization.find 574

idirect_operable_teams = idirect.teams.where.not(id: 836)
iserve_operable_teams = iserve.teams

# remove old templates first

idirect_operable_teams.each { |t| t.loan_file_templates.destroy_all }
iserve_operable_teams.each { |t| t.loan_file_templates.destroy_all }

iserve_operable_teams.each do |dst_team|
  src_team.loan_file_templates.order(:id).each do |loan_file_template|
    LoanFileTemplates::CopyTemplateToAnotherTeam.perform(loan_file_template, dst_team)
  end
end

idirect_operable_teams.each do |dst_team|
  src_team.loan_file_templates.order(:id).each do |loan_file_template|
    LoanFileTemplates::CopyTemplateToAnotherTeam.perform(loan_file_template, dst_team)
  end 
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment