我正在使用 Rails 和 jQuery mobile 编写移动 Web 应用程序。我正在使用 HTTParty 在运行时从 Amazon AWS S3 读取我的所有数据。
我需要渲染的屏幕之一就是直接的 html,它可以并且通常确实嵌入了图像,这些图像托管在 S3 上的同一文件夹中。这就是我的问题所在。我可以很容易地使用 HTTParty 拉入 html 并使用 html_safe 选项来呈现它,但图像不会呈现,因为它们是相对路径名。所以我一直在试图找到解决这个问题的方法。
我尝试了多种方法,但我主要是在研究使用 html 标签来让图像指向正确的位置。问题是我不能指定一个基本标签,然后在页面上有其他链接,因为他们然后使用相同的基地并且链接没有指向正确的位置。因此,我查看了框架集和框架,并将基本标签仅指向框架,我相信我正确使用了它,但无济于事。我尝试使用但无济于事。
所以基本上我正在寻找一种方法,如果不清楚的话,我可以在我从 S3 读取的 html 字符串中设置相对路径名的基础。我愿意接受任何建议!并提前感谢您阅读并尝试解决这个非常具体的问题!
哦,还有一件事,当我用 Firebug 查看页面时,标题中的第一行是一个基本标记,其 href 设置为当前页面。我不知道它是从哪里来的,但我猜是 Rails 把它扔在那里的?我不知道这是否重要,因为我随后在其下方放置了另一个基本标签,并带有 yield :intro_base? 或者这是我的问题之一,因为那里有冲突?
然后是代码:我的“介绍”方法:
def intro
@intros = []
@app_config.intro_screens.each do |intro_screen|
intro_screen_response =
ApplicationController.get("#{@diandr_url}/#{intro_screen['filename']}.html")
@intros << intro_screen_response.body
end
@intros.reverse!
@intros_length = @intros.length
respond_to do |format|
format.html
end
end
我的“intro.html.erb”文件:
<% page_num = params[:id].to_i %>
<% content_for :intro_base do %>
<base href="https://s3.amazonaws.com/our_bucket_name<%=@dir_url%>/" target="intro" />
<% end %>
<% content_for :mobile_header do %>
*some jQuery mobile paging and header stuff is in here, shouldn't matter*
<% end %>
<% content_for :mobile_content do %>
<!-- <iframe src=<%= @intros[page_num] %> height="100%" width="100%"> -->
<!-- <p> This browser does not support iframes </p> -->
<!-- </iframe> -->
<frameset cols="100%">
<frame name="intro" <%= @intros[page_num].html_safe %>
</frameset>
<% end %>
我的布局的标题:
<head>
<title> our Mobile App </title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- These are the jQuery Mobile scripts -->
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js">
</script>
<%= yield :intro_base %>
<%= stylesheet_link_tag "master" %>
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>