わかりました、私は今うまくいくものを持っています。適切な場所で私を始めてくれた@danivovichに感謝します。私が最初にやらなければならなかったのは、HTMLがXHTMLでエイリアス化されないように、mime_types.rbのMimeタイプを分類することでした。
module Mime
remove_const('HTML') # remove this so that we can re-register the types
end
Mime::Type.register "text/html", :html
Mime::Type.register "application/xhtml+xml", :xhtml
これをアプリケーションコントローラーに追加しました。
before_filter :negotiate_xhtml
after_filter :set_content_type
def negotiate_xhtml
@serving_polyglot = false
if params[:format].nil? or request.format == :html
@serving_polyglot = ((not request.accepts.include? :xhtml) or params[:format] == 'html')
request.format = :xhtml
end
end
def set_content_type
if @serving_polyglot
response.content_type = 'text/html'
end
end
これにより、クライアントがXHTMLを受け入れない場合、またはHTMLが明示的に要求されていない限り、XHTMLは常にそのようにサーバー化されます。HTMLは常に、ポリグロットとして機能するXHTMLです。@serving_polyglot変数は、切り替えが必要なビューで使用できます。
これは、Chrome、Safari、Firefox、Opera、IE[6-8]で機能しています。