给出以下形式:
<form>
<input name="foo" value="bar">
<input name="hello" value="hello world">
</form>
Run Code Online (Sandbox Code Playgroud)
我可以使用$.param( .. )构造来序列化表单:
$.param( $('form input') )
=> foo=bar&hello=hello+world
Run Code Online (Sandbox Code Playgroud)
如何用JavaScript反序列化上面的String并获取哈希值?
例如,
$.magicFunction("foo=bar&hello=hello+world")
=> {'foo' : 'bar', 'hello' : 'hello world'}
Run Code Online (Sandbox Code Playgroud)
我的app/models文件夹中有很多模型.我想稍微清理一下这个文件夹.在子文件夹中移动彼此属于的模型.问题是按照惯例,模型类被命名为相应的模块.
例如
app/models/blog/post.rb
app/models/blog/comment.rb
app/models/user.rb
以便:
应用程序/模型/博客/ post.rb
class Post < ActiveRecord
end
Run Code Online (Sandbox Code Playgroud)
并不是
class Blog::Post < ActiveRecord
end
Run Code Online (Sandbox Code Playgroud) 我正在开发一个Rails 2.3,Ruby 1.9.1 webapplication,它在每个请求之前进行了大量的计算.对于每个请求,它必须计算具有300个节点和~1000个边的图.图形及其所有节点,边和其他对象都为每个请求(~2000个对象)初始化 - 实际上它们是使用Marshal.load(Marshal.dump())从未计算的缓存图中克隆的.
性能在这里是一个很大的问题.现在整个请求平均需要150毫秒.然后我看到在请求期间,部分计算随机需要更长时间.假设这可能是GarbageCollector,我将请求包装在GC.disable和GC.enable中,以便请求等待使用garbagecollecting直到计算和渲染完成.
def query
GC.disable
calculate
respond_to do |format| format.html {render} end
GC.enable
end
Run Code Online (Sandbox Code Playgroud)
现在平均请求大约需要100毫秒(减少50毫秒).
但我不确定这是一个好的/稳定的解决方案,我认为这样做肯定有缺点.有没有人遇到过类似问题或看到上述代码有问题?
使用ruby regexp我得到以下结果:
>> 'foobar'[/o+/]
=> "oo"
>> 'foobar'[/o*/]
=> ""
Run Code Online (Sandbox Code Playgroud)
但:
>> 'foobar'[/fo+/]
=> "foo"
>> 'foobar'[/fo*/]
=> "foo"
Run Code Online (Sandbox Code Playgroud)
文档说:
*:前面
+的重复零次或多次:前面的一次或多次重复
所以我希望'foobar'[/ o*/]返回与'foobar'相同的结果[/ o + /]
有没有人对此有解释