【发布时间】:2017-11-19 01:20:10
【问题描述】:
root.rb
root 'builders#result'
post 'builders/calc'
builders_controller.rb
class BuildersController < ApplicationController
def result
end
def calc
@hash = {0 => ["a", "b", "c"],1 => ["x", "y", "z"]}
@text = @hash.values.map{ |v| v.join(',') }.join("\n")
@result = @text
end
end
result.html.erb
<div id="total"></div>
calc.js.erb $('#total').html('')
如果我像@result = @hash.values 这样发布@result
我可以看到结果为[["a", "b", "c"], ["x", "y", "z"]],但@result = @hash.values.map{ |v| v.join(',') }.join("\n") 不起作用?
.join("\n") 似乎有问题,但我需要保存选项才能从新行查看每个格式化值
有什么办法吗? 谢谢
【问题讨论】:
标签: jquery ruby-on-rails hash