Skip to content

Meta attributes parse error` #395

@avra911

Description

@avra911

In my instance I had issues parsing the meta attributes in edit page.

undefined method `each' for "{}":String

I fixed that by using:

diff --git a/app/views/shared/_meta_form.html.haml b/app/views/shared/_meta_form.html.haml
index 00d8c0c..7c7847f 100644
--- a/app/views/shared/_meta_form.html.haml
+++ b/app/views/shared/_meta_form.html.haml
@@ -1,5 +1,15 @@
+- require 'json'
 #js-meta-table.invoice-table
-  - instance.meta.each do |key, value|
+  - meta_data = {}
+  - if instance.meta.is_a?(String) && !instance.meta.empty?
+    - begin
+      - # Convert Ruby hash string to valid JSON format
+      - valid_json = instance.meta.gsub("=>", ":").gsub(/(['"])(.*?)\1/, '"\2"')
+      - meta_data = JSON.parse(valid_json) rescue {}
+    - rescue JSON::ParserError => e
+      %p Error parsing JSON: #{e.message}
+
+  - meta_data.each do |key, value|
     .invoice-row.js-meta
       .invoice-col.form-group
         = text_field :key, "", value: key, class: 'form-control', placeholder: "Key"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions