diff --git a/app/controllers/template_options_controller.rb b/app/controllers/template_options_controller.rb index 61d6f42017..42431cb4ff 100644 --- a/app/controllers/template_options_controller.rb +++ b/app/controllers/template_options_controller.rb @@ -28,7 +28,7 @@ def index if org.present? && !org.new_record? # Load the funder's template(s) minus the default template (that gets swapped # in below if NO other templates are available) - @templates = Template.latest_customizable.where(org_id: funder.id, is_default: false).to_a + @templates = Template.latest_customizable.where(org_id: funder.id, is_default: false).sort_by(&:title).to_a # Swap out any organisational cusotmizations of a funder template @templates = @templates.map do |tmplt| customization = Template.published @@ -47,7 +47,7 @@ def index # If the no funder was specified OR the funder matches the org # if funder.blank? || funder.id == org&.id # Retrieve the Org's templates - @templates << Template.published.organisationally_visible.where(org_id: org.id, customization_of: nil).to_a + @templates << Template.published.organisationally_visible.where(org_id: org.id, customization_of: nil).sort_by(&:title).to_a @templates = @templates.flatten.uniq else # if'No Primary Research Institution' checkbox is checked, @@ -63,9 +63,8 @@ def index customization ||= Template.default @templates.select! { |t| t.id != Template.default.id && t.id != customization.id } # We want the default template to appear at the beggining of the list - @templates.unshift(customization) + @templates.unshift(customization).uniq end - @templates = @templates.uniq.sort_by(&:title) end # rubocop:enable Metrics/AbcSize, Metrics/MethodLength # rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity