Rails と jQuery モバイルを使用してモバイル Web アプリケーションを作成しています。HTTParty を使用して、実行時に Amazon AWS S3 からすべてのデータを読み取っています。
私がレンダリングする必要がある画面の 1 つは、S3 の同じフォルダーにホストされている画像を埋め込むことができ、通常は実際に埋め込まれているストレート html です。これが私の問題です。HTTParty を使用して html を簡単に取得し、html_safe オプションを使用してレンダリングできますが、画像は相対パス名であるためレンダリングされません。だから私はこれを回避する方法を見つけようとしてきました。
私は複数のことを試しましたが、主にhtmlタグを使用して画像が正しい場所を指すようにすることを検討していました。問題は、ベース タグを指定してページに他のリンクを設定できないことです。同じベースを使用し、リンクが正しい場所を指していないためです。そこで、フレームセットとフレームを調べて、ベースタグをフレームだけに向けました。これは正しく使用したと思いますが、役に立ちませんでした。使ってみましたがだめでした。
基本的に、S3から読み込んだhtml文字列に相対パス名のベースを設定できる方法を探していますが、それが明確でない場合。私はどんな提案にもオープンです!そして、読んでくれてありがとう、この非常に具体的な問題を解決してみてください!
ああ、もう 1 つ、Firebug でページを見ると、ヘッダーの最初の行は、href が現在のページに設定されたベース タグです。どこから来ているのかわかりませんが、レールがそこに投げ込んでいると思いますか? その下に別のベースタグをyield :intro_base? で配置したため、これが問題かどうかはわかりません。それとも、そこに競合があるので、それは私の問題の1つですか?
そして、コードがありました:私の「イントロ」メソッド:
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 %>