我希望在应用程序<%=yield%> 中呈现一个外部网页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 %>
我收到以下错误:incompatible character encodings: UTF-8 and ASCII-8BIT
甚至有可能做到这一点吗?问题是这些价格会更新并在 excel 文件中接收,所以如果我只是将它们放在 html 表中,需要做很多工作来调整它们。