In Rails 3, respond_to and format.all works differently than Rails 2?

后端 未结 3 666
栀梦
栀梦 2021-02-05 05:10

the code

respond_to do |format|
  format.html
  format.json { render :json => @switches }
  format.xml { render :xml => @switches.to_xml }
  format.all { r         


        
3条回答
  •  一向
    一向 (楼主)
    2021-02-05 05:36

    The following works for me. I believe you have to specify the "render" part for html explicitly or it will use the format.any.

    respond_to do |format|
      format.html { render :html => @switches }
      format.json { render :json => @switches }
      format.xml  { render :xml  => @switches }
      format.all  { render :text => "we only have html, json, and xml" }
    end
    

提交回复
热议问题