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 $(&#39; #total&#39;)。html(&#39;&lt;%= @result%&gt;&#39;)
如果我发布@result就像@result = @hash.values
一样
我可以看到结果为[["a", "b", "c"], ["x", "y", "z"]]
,但@result = @hash.values.map{ |v| v.join(',') }.join("\n")
无效?
似乎与.join("\n")
有问题,但我需要保存选项以查看新行中的每个格式化值
任何修复? 感谢
答案 0 :(得分:0)
您可以使用simple_format帮助:
<%= simple_format(@result) %>
在jQuery中还有一个pretty neat code
您可能感兴趣的另一个答案:raw vs. html_safe vs. h to unescape html