我已经完成了这一千次,但我仍然不熟悉render :json手柄弦如何.
要设置范围,我们来谈谈Rails 3
这就是它现在的行为方式:
...
render :json => 'This is the string'
...
Run Code Online (Sandbox Code Playgroud)
将返回浏览器:
This is the string
Run Code Online (Sandbox Code Playgroud)
这实际上不是有效的JSON响应:S
理想情况下它应该呈现这样的东西:
"This is the string"
Run Code Online (Sandbox Code Playgroud)
铁轨指南甚至说:
您不需要在要渲染的对象上调用to_json.如果使用:json选项,render将自动为您调用to_json.
并且调用"This is the string".to_json实际上正在"\"This is the string\""按预期返回.
"This is the string".to_json #=> "\"This is the string\""
Run Code Online (Sandbox Code Playgroud)
我错了吗?
我正在阅读 W3 PNG 规范(从头开始创建一个 PNG 库),我终于找到了如何创建绿色 1x1 图像。
现在我正在尝试创建一个更大的混合红色、绿色和蓝色像素的图像。假设一个 4x4 图像。可悲的是,我将所有像素混合在一起,其中一些是黑色或粉红色。
细节:
*IDATA 块:
**按位结果:
alpha<<24 | red<<16 | green<<8 | blue
Run Code Online (Sandbox Code Playgroud)
alpha、蓝色、绿色和红色取值从 0 到 255
这有什么问题?
在我的Rails 3 app控制器上,我有以下代码:
array = []
Location.all.each{|x|array<<x.city.html_safe}
@data_dump = array
Run Code Online (Sandbox Code Playgroud)
在Rails控制台中,它看起来很干净:
["Littelside", "Tessmouth"]
Run Code Online (Sandbox Code Playgroud)
在我看来,@ data_dump对象被编码:
["Littelside", "Tessmouth"]
Run Code Online (Sandbox Code Playgroud)
你怎么清理这个烂摊子?我希望我的对象在视图中,以对象在终端中返回.提前致谢!