How to take out the value of the hash obtained by the controller of reails in view and display it

Asked 2 years ago, Updated 2 years ago, 63 views

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.

ruby-on-rails ruby html json erb

2022-09-30 17:00

1 Answers

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


2022-09-30 17:00

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.