0

残りのシステムで条件付き GETting のサポートを実装しようとしているときに、 fresh_when と stale? に遭遇しました。メソッド。

次のコードは 304 で正常に動作し、それ以上のレンダリングは行いません: format.html # show.html.erb } end end

ただし、1.xml にアクセスすると、リソースを 2 回レンダリングしようとします。

if stale?(:etag => resource, :last_modified => resource.updated_at.utc)
  respond_to do |format|
    format.html # show.html.erb
    format.xml  { 
      render :xml => @order.to_xml(:controller => self, :except => [:paid_at]) 
      }
  end
end

エラーメッセージ:

ActionController::OrdersController#show の DoubleRenderError

アクションごとに 1 回だけレンダリングまたはリダイレクトできます

RAILS_ROOT: /Users/guilherme/Documents/ruby/restfulie-test アプリケーション トレース | フレームワーク トレース | 完全なトレース

/Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/base.rb:900:in render_without_benchmark' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/benchmarking.rb:51:inrender' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active_support /core_ext/benchmark.rb:17:in ms' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active_support/core_ext/benchmark.rb:10:inrealtime' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active_support/core_ext/benchmark.rb:17:in ms' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/benchmarking.rb:51:inrender' /Library/Ruby/Gems /1.8/gems/actionpack-2.3.4/lib/action_controller/base.rb:1331:in send' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/base.rb:1331:inperform_action_without_filters' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/filters.rb:617 :in call_filters' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/filters.rb:610:inperform_action_without_benchmark' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/benchmarking.rb:68:in perform_action_without_rescue' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active_support/core_ext/benchmark.rb:17:inms' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4 /lib/active_support/core_ext/benchmark.rb:10:inrealtime' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active_support/core_ext/benchmark.rb:17:inms' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/benchmarking.rb:68:in perform_action_without_rescue' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/rescue.rb:160:inperform_action_without_flash' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib /action_controller/flash.rb:146:perform_action' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/base.rb:532:in送信中' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/base.rb:532:process_without_filters' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/filters.rb:606:in処理中' /Library/Ruby/Gems/1.8 /gems/actionpack-2.3.4/lib/action_controller/base.rb:391:process' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/base.rb:386:in呼び出し中' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/routing/route_set.rb:437 :in `call'

助言がありますか?

よろしく

4

1 に答える 1

0

これに対する解決策が見つかったかどうかはわかりませんが、jsのレンダリングでまったく同じ問題が発生しました

私が見つけた解決策は、逆を使用することでした:

def index
  if stale?(:etag => [request.host],
            :public => true)
    respond_to do |format|
      format.js
    end
  end
end

もちろん、[request.host] を置き換えて、鮮度を判断するために使用しているものは何もありません。

于 2010-03-19T00:59:05.333 に答える