Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在.html.erb文件中获取错误的输出_Html_File_Gem_Erb - Fatal编程技术网

在.html.erb文件中获取错误的输出

在.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文件中使用同一行时 <%=

我正在使用“主动装运”宝石。当我使用带有以下行的.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文件中使用同一行时

<%= 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%>

,


我得到了期望的输出: