Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/52.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
在RoR项目中将外部html页面呈现为主体:Encoding::CompatibilityError_Html_Ruby On Rails_Render - Fatal编程技术网

在RoR项目中将外部html页面呈现为主体:Encoding::CompatibilityError

在RoR项目中将外部html页面呈现为主体:Encoding::CompatibilityError,html,ruby-on-rails,render,Html,Ruby On Rails,Render,我希望在应用程序中呈现外部网页rates.appiclife.com 我试过这个: 我在pages_controller.rb中放置了以下方法 def fetch_url(url) r = Net::HTTP.get_response( URI.parse( url ) ) if r.is_a? Net::HTTPSuccess r.body else nil end end 在同一文件中: def showexternal @s

我希望在应用程序中呈现外部网页rates.appiclife.com

我试过这个:

我在pages_controller.rb中放置了以下方法

def fetch_url(url)
    r = Net::HTTP.get_response( URI.parse( url ) )
    if r.is_a? Net::HTTPSuccess
      r.body
    else
      nil
    end
  end
在同一文件中:

def showexternal
  @snippet = fetch_url "http://rates.appiclife.com/"
end
在showexternal.html.erb视图/页面中:

<%= @snippet %>

我得到以下错误:
不兼容的字符编码:UTF-8和ASCII-8BIT


甚至有可能做到这一点吗?问题是,这些价格是在excel文件中更新和接收的,因此如果我将它们放在html表格中,需要做大量的工作来调整它们。

您应该能够使用Nokogiri将请求-响应解析为字符串,然后使用它做任何您想做的事情。您可以在此处找到快速教程:


您应该能够使用Nokogiri将请求-响应解析为字符串,然后使用它执行任何操作。您可以在此处找到快速教程: