The DB contains data such as {"params":{"name":"apple", "color":"red"}
.
"Regarding this, I would like to know how to get hash values such as ""apple"" and ""red"" on the views of rails."
Since the data is probably in json format, if JSON.parse({"params":{"name":"apple", "color":"red")
,
{"name":"apple", "color":"red"}
can be retrieved, but
JSON.parse({"params":{"name":"apple", "color":"red"}})["name"]
cannot also display "apple".
Thank you for your cooperation.
h={"params":{"name":"apple", "color":"red"}}
h.dig:params, :name#=>"apple"
Is this possible?dig
is a method for retrieving values from nested hashes like the one above
© 2024 OneMinuteCode. All rights reserved.