diff --git a/app/controllers/org_admin/templates_controller.rb b/app/controllers/org_admin/templates_controller.rb index ba6c281..8cc5c73 100644 --- a/app/controllers/org_admin/templates_controller.rb +++ b/app/controllers/org_admin/templates_controller.rb @@ -114,13 +114,22 @@ if current != @template render(status: :forbidden, json: { msg: _('You can not edit a historical version of this template.')}) else + template_links = nil + begin + template_links = JSON.parse(params["template-links"]) if params["template-links"].present? + rescue JSON::ParserError + render(status: :bad_request, json: { msg: _('Error parsing links for a template') }) + return + end + # TODO dirty check at template model instead of here for reusability, i.e. method dirty? passing a template object if @template.description != params["template-desc"] || - @template.title != params[:template][:title] + @template.title != params[:template][:title] || + @template.links != template_links @template.dirty = true end @template.description = params["template-desc"] - @template.links = JSON.parse(params["template-links"]) if params["template-links"].present? + @template.links = template_links if template_links.present? # If the visibility checkbox is not checked and the user's org is a funder set the visibility to public # otherwise default it to organisationally_visible diff --git a/app/views/org_admin/templates/_edit_template.html.erb b/app/views/org_admin/templates/_edit_template.html.erb index 6af0fbb..0862398 100644 --- a/app/views/org_admin/templates/_edit_template.html.erb +++ b/app/views/org_admin/templates/_edit_template.html.erb @@ -66,7 +66,7 @@ max_number_links: MAX_NUMBER_LINKS_SAMPLE_PLAN, tooltip: _('Add links to sample plans if provided by the funder.') }) %> - <%= hidden_field_tag('template-links', value: template.links) %> + <%= hidden_field_tag('template-links', ActiveSupport::JSON.encode(template.links)) %> <% end %>
diff --git a/app/views/shared/_links.html.erb b/app/views/shared/_links.html.erb index b20a916..67c3b98 100644 --- a/app/views/shared/_links.html.erb +++ b/app/views/shared/_links.html.erb @@ -17,24 +17,28 @@
<% links = [{ "link" => "", "text" => "" }] if links.length == 0 %> - <% i = 0 %> - <% links.each do |l| %> -