You could use:
eval(params["comment_id"])[:value]
=> 1
The eval would convert the string value of params["comment_id"]
into an actual hash, and then you can easily retrieve the value from it.
Question
I have this code in my view:
<%= hidden_field_tag :comment_id, '1'%>
It essentially creates this for params
params = {"commit"=>"No Phrase to Add", "comment_id"=>"{:value=>1}"}
I want to extract the comment_id
of 1
from the above hash. params[:comment_id][:value]
throws an error, because I'm not looking at the key directly but a hash as a string instead.
How can I remove the value
key or access the comment_id
of 1
above?
goal : "comment_id" => 1
La solution
You could use:
eval(params["comment_id"])[:value]
=> 1
The eval would convert the string value of params["comment_id"]
into an actual hash, and then you can easily retrieve the value from it.