将JSON哈希转换为要在rails视图中使用的URL



我使用的API在响应中有一个URL(JSON哈希)。我正在尝试获取响应,解析URL,并在rails视图中的link_to助手中使用该URL。我目前的JSON解析没有达到目的。

# The Response
{"url":"https://demo.foobar.net/t=54e85a9f-008b-481c-986d-69881208713e"}
# Controller Action to Parse
@url = JSON.parse(response.to_json)
# Rails View
<%= link_to "Sign Document", @url %>
# Rendered HTML
<a href="/?url=https%3A%2F%2Fhttps://demo.foobar.net/t=54e85a9f-008b-481c-986d-69881208713e">Click Here!</a>

我需要解析JSON哈希,以确保rails link_to助手的输出为:

 <a href="https://demo.foobar.net/t=54e85a9f-008b-481c-986d69881208713e">Click Here!</a>

为什么要将响应转换为json,然后再次解析它。U可以像一样获得url的值

@url = response["url"]

最新更新