2009-11-30 8 views
0

Tout en essayant d'implémenter le support pour la mise en place conditionnelle dans un système de repos, nous avons rencontré le fresh_when et le fade? méthodesfresh_when in ruby ​​ne fonctionne pas avec le rendu xml

Le code suivant fonctionne très bien avec 304 et non plus rendu: si rassis (: ETAG => ressource,: last_modified => resource.updated_at.utc)? respond_to do | Format | format.html # show.html.erb } fin fin

Mais l'accès 1.xml va essayer de rendre deux fois la ressource:

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 

Le message d'erreur:

ActionController: : DoubleRenderError dans OrdersController # show

Peut uniquement rendre ou rediriger une fois par action

RAILS_ROOT:/Users/guilherme/Documents/ruby ​​/ restfulie-test Application Trace | Trace de cadre | Trace complète

/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:in rendre » /Library/Ruby/Gems/1.8/gems/activesupport -2.3.4/lib/support_active/core_ext/benchmark.rb: 17: en ms' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active_support/core_ext/benchmark.rb:10:in temps réel ' /Library/Ruby/Gems/1.8/gems/activesupport-2.3.4/lib/active_support/core_ext/benchmark.rb:17 : dans ms' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/benchmarking.rb:51:in Rendu ' /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:in perform_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:in perform_action_without_benchmark ' /Library/Ruby/Gems/1.8/gems/actio npack-2.3.4/lib/action_controller/benchmarking.rb: 68: dans perform_action_without_rescue' /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: dans realtime' /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:68:in perform_action_without_rescue' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/rescue.rb:160:in perform_action_without_flash' /Library/Ruby/Gems/1.8/gems/actionpack- 2.3.4/lib/action_controller/flash.rb: 146: dans perform_action' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/base.rb:532:in envoyer ' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/base.rb:532:in process_without_filters' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/filters.rb:606:in processus' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/base.rb:391:in process' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/lib/action_controller/base.rb:386:in appel ' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.4/ lib/action_controller/routing/route_set.rb: 4 37: dans `call '

Des suggestions?

Cordialement

+0

Pourquoi avez-vous '': controller => self' transmis à 'to_xml'? – BaroqueBobcat

+0

Restfulie ... github.com/caelum/restfulie –

Répondre

0

Je ne sais pas si vous avez trouvé la solution à ce sujet, mais je viens d'avoir le problème même rendu js

la solution que j'ai trouvé était d'utiliser l'inverse:

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

en remplaçant [request.host] par tout ce que vous utilisez pour déterminer la fraîcheur, bien sûr.

Questions connexes