在 ror 中渲染文本转换字符串
render text convert strings in ror
我渲染 json 没有 object 标题。所以我尝试将其呈现为如下文本
render :text=>
[{
"id": "0",
"heading": "Trending this Week",
"title": "Prost Brew Pub",
"place": "Sholinganallur",
"image": "http://192.168.0.103/test2/blur.jpg",
"rating": 4.3,
"amount": "Rs. 1800 for two people",
"review": "320 Reviews",
"photos": "630 Photos",
"genre": ["British", "Mexican", "Continental"]
},...
把上面的转换成下面的样子
[{:id=>"0", :heading=>"Trending this Week", :title=>"Prost Brew Pub", :place=>"Sholinganallur", :image=>"http://192.168.0.103/test2/blur.jpg", :rating=>4.3, :amount=>"Rs. 1800 for two people", :review=>"320 Reviews", :photos=>"630 Photos", :genre=>["British", "Mexican", "Continental"]}
为什么将 "id": "0"
转换为 :id=>"0"
?
如何在不做任何更改的情况下渲染上述数组?提前致谢。
是否有可用的渲染方法来获取没有标题的 object?
您的“:text”是一个散列数组。所以 Ruby 是以 Hash 语法呈现它。如果你想要 json 你应该渲染 json
而不是 text
.
render json: @object, status: :ok
我渲染 json 没有 object 标题。所以我尝试将其呈现为如下文本
render :text=>
[{
"id": "0",
"heading": "Trending this Week",
"title": "Prost Brew Pub",
"place": "Sholinganallur",
"image": "http://192.168.0.103/test2/blur.jpg",
"rating": 4.3,
"amount": "Rs. 1800 for two people",
"review": "320 Reviews",
"photos": "630 Photos",
"genre": ["British", "Mexican", "Continental"]
},...
把上面的转换成下面的样子
[{:id=>"0", :heading=>"Trending this Week", :title=>"Prost Brew Pub", :place=>"Sholinganallur", :image=>"http://192.168.0.103/test2/blur.jpg", :rating=>4.3, :amount=>"Rs. 1800 for two people", :review=>"320 Reviews", :photos=>"630 Photos", :genre=>["British", "Mexican", "Continental"]}
为什么将 "id": "0"
转换为 :id=>"0"
?
如何在不做任何更改的情况下渲染上述数组?提前致谢。
是否有可用的渲染方法来获取没有标题的 object?
您的“:text”是一个散列数组。所以 Ruby 是以 Hash 语法呈现它。如果你想要 json 你应该渲染 json
而不是 text
.
render json: @object, status: :ok