所以用 Rails 不就好了 https://ruby-china.org/topics/25822
https://github.com/mongodb/bson-ruby/blob/master/CHANGELOG.md#304
bson-ruby 3.0.4 已经修复了。
勇士!欢迎来到前端高原,你想走哪一条路继续冒险?
Foreman export 那步做了没?
HTML
<div id="dialog-quit" class="dialog">
<div class="title">
<img src="close.gif" alt="点击可以关闭" />亲爱的提示条
</div>
<div class="content">
<img src="delete.jpg" alt="" />
<span>您真的要GG吗?</span>
</div>
<div class="bottom">
<input id="Button2" type="button" value="确定" class="btn"/>
<input id="Button3" type="button" value="取消" class="btn"/>
</div>
</div>
JavaScript(jQuery)
$('#dialog-quit')
#17 楼 @wl1991724 要一次更改全局可以覆盖 ActiveSupport::TimeWithZone
,但你要确定会不会破坏其它地方。
2015-05-15T09:38:55.000Z
就是 JavaScript 能解析的 ISO-8601 标准格式,如果不想违背 DRY,是不是不应该修改这个格式呢? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse
方法一:覆盖 Model 的 as_json
方法
http://api.rubyonrails.org/classes/ActiveModel/Serializers/JSON.html
def as_json
super.merge(
created_at: created_at.strftime( FORMAT_STRING ) # http://ruby-doc.org/core-2.2.0/Time.html#method-i-strftime
)
end
方法二:用 https://github.com/rails/jbuilder 逐个字段定制。
我觉得楼主主要纠结的地方是,这是字符串的终端表示(irb,浏览器 console):
"string"
这是字符串的纯文本表示(API 输出):
string
这两个是一样的。
#9 楼 @wl1991724 jsonArray 是个 Java 内存中的对象,最终输出的时候是转化为字符串的。你觉得不需要 JSON.parse 是因为 ajax 库已经把这件事做了。
你在 Ruby 终端试试:
puts "[\"AA_AA\",\"AA_AA\",\"AA_AA\",\"AA_AA\",\"AA_AA\",\"AA_AA\",\"AA_AA\",\"AA_AA\",\"AA_AA\",\"AA_AA\"]"
是不是要的 JSON?
#16 楼 @flingfox63 对啊,用 Grape 写,代码量也没有少,routes 的代码都移到 grape 里面,调用栈增加了,跟 Rails 的 Filter 和 Helper 不通用了,有人解释下 Grape 有什么好处么?
提交 url,后台抓。
#6 楼 @wl1991724 另外,firebug 也是终端,字符串也要加引号。你用 javascript 的 json 解析器解析看看。
> JSON.parse("[\"AA_AA\",\"AA_AA\",\"AA_AA\",\"AA_AA\",\"AA_AA\",\"AA_AA\",\"AA_AA\",\"AA_AA\",\"AA_AA\",\"AA_AA\"]")
["AA_AA", "AA_AA", "AA_AA", "AA_AA", "AA_AA", "AA_AA", "AA_AA", "AA_AA", "AA_AA", "AA_AA"]
#6 楼 @wl1991724 是不是写了两重 to_json
了?render json:
就会自动调用 to_json
。你用虚构的代码我看不出问题,正常 render json: models
就是输出 json。
真实例子:
如果在终端输出,因为 json 是个字符串,所以两边就会加上引号。如果在浏览器输出,两边就没有引号,因为不需要。
#2 楼 @wl1991724 json 就是字符串啊。
array.to_json
respond_to do |format|
format.json { render json: array }
end
要用校验应该平铺在 User Model 或者抽取成 AdditionInfo Model。
#6 楼 @killernova 你看链接。
#4 楼 @killernova https://github.com/killernova/blog/tree/master/app
uploader 目录在哪?
uploader 目录没 check in
一个用 Rails 构建 API 的真实例子 https://github.com/rubygems/rubygems.org
“发现并没有什么卵用” <- 我看到这句话很想删贴,正常说话不行吗?