2010-12-20 15 views
0

私は、ユーザがURLパラメータを介してフォーマットを渡すことを可能にするスクリプトを書いています。私は必要に応じてJSONとXMLを動作させていますが、YAMLを動作させることはできません。何らかの理由でRails 3レンダリングの問題

case params[:format] 
     when "xml" then respond_with(@labels) 
     when "json" then respond_with(@labels_hash.to_json) 
     when "yaml" then render :text => @labels_hash.to_yaml 
     end 

私は私のスクリプトファイルをダウンロード強制しようとし、その後、私のURLでformat=yamlを渡すとき。これが起こる理由は何ですか?

ワーキングコード:

case params[:format] 
     when "xml" then respond_with(@labels) 
     when "json" then respond_with(@labels_hash.to_json) 
     when "yaml" then respond_with(@labels_hash) do |format| 
      format.yaml { render :text => @labels_hash.to_s } 
     end 
     end 

答えて

1

試してみてください。

がコントローラにrespond_to :yaml:yamlの追加、および:

respond_to do |format| 
    ....other formats.... 
    format.yaml { render :yaml => @labels_hash } 
end 
+1

私はそれを試してみましたが、まだ、ファイルをダウンロードし、強制しようとしています。 – dennismonsewicz

+0

私はそれをcURL呼び出しを使って動作させました。私は作成したYAMLをブラウザで表示しようとしていましたが、ブラウザがYAML MIMEタイプの解釈方法を知らないとは思わなかった – dennismonsewicz

関連する問題