在.html.erb文件中获取错误的输出
我正在使用“主动装运”宝石。当我使用带有以下行的.rb文件时在.html.erb文件中获取错误的输出,html,file,gem,erb,Html,File,Gem,Erb,我正在使用“主动装运”宝石。当我使用带有以下行的.rb文件时 puts res.rates.sort_by(&:price).collect {|rate| [rate.service_name, (@bank.get_rate(res.rate_estimates[0].currency,:USD) * (rate.price).to_f/100).round(2)]}, 我得到以下输出: 但是,当我在.html.erb文件中使用同一行时 <%=
puts res.rates.sort_by(&:price).collect
{|rate| [rate.service_name,
(@bank.get_rate(res.rate_estimates[0].currency,:USD)
* (rate.price).to_f/100).round(2)]},
我得到以下输出:
但是,当我在.html.erb文件中使用同一行时
<%= res.rates.sort_by(&:price).collect
{|rate| [rate.service_name,
(@bank.get_rate(res.rate_estimates[0].currency,:USD)
* (rate.price).to_f/100).round(2)]}%>,
,
我在视图中得到以下输出:
有人能帮我解决这个问题吗。如何在.html.erb文件中正确显示文本。谢谢。Ruby对象没有显示在erb中,我想是因为您没有足够的分隔符。请尝试以下方法:
<% res.rates.sort_by(&:price).collect %>
<%= {|rate| [rate.service_name,
(@bank.get_rate(res.rate_estimates[0].currency,:USD)
* (rate.price).to_f/100).round(2)]} %>
多亏了凯瑟琳,我将代码改为:
<p><%res.rates.sort_by(&:price).each do |rate|%>
<%= rate.service_name%>,
<%=(@bank.get_rate(res.rate_estimates[0].currency,:USD)
* (rate.price).to_f/100).round(2)%> </p><br/>
<%end%>
,
我得到了期望的输出: