Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meta attributes parse error` #395

Open
avra911 opened this issue Dec 19, 2024 · 0 comments
Open

Meta attributes parse error` #395

avra911 opened this issue Dec 19, 2024 · 0 comments

Comments

@avra911
Copy link
Contributor

avra911 commented Dec 19, 2024

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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant