which is not the one that i really want. My question is how to keep the backslash after save in my db?
这不是我真正想要的那个。我的问题是如何在我的数据库中保存后保留反斜杠?
This is exactly what i want: "patterns":[".+\.runsheet\..+”]
这正是我想要的:“模式”:[“。+ \。runsheet \ .. +”]
I've try with this: <%= hidden_field_tag "ng_b2b_configuration[value][endpoints][][patterns][]", raw(".+\\\\.runsheet\\\\..+"), class: "val_runsheet_all" %> and the result: "patterns":[\".+\\.runsheet\\..+\”]
value=".+\.runsheet\..+" in the HTML will end up as '.+\.runsheet\..+' in Ruby so you're being confused somewhere. Nothing you do will (without trickery) will give you a string like:
in Ruby or JSON. Backslashes have special meaning in both Ruby double quoted strings and JSON formatted strings. Neither one needs a backslash to escape a . so neither will put it there. But because \ has a special meaning as an escape character in both Ruby double quoted strings and JSON, a single \ will look like \\ because both have to escape the special mean of \ by, well, escaping the escape character.
Then you can throw in some to_json calls (again using puts to see the results so that you avoid the escaping that inspect will use) and you'll see similar things happening.