在ruby中不使用xml呈现时刷新
在尝试在rest系统中实现对有条件获取的支持时,我们遇到了新鲜和过时的问题?方法 以下代码适用于304,不需要进一步渲染: 如果过时(:etag=>resource,:last\u modified=>resource.updated\u at.utc) 回应待办事项|格式| format.html#show.html.erb } 终止 结束 但是访问1.xml将尝试呈现资源两次:在ruby中不使用xml呈现时刷新,ruby,caching,etag,Ruby,Caching,Etag,在尝试在rest系统中实现对有条件获取的支持时,我们遇到了新鲜和过时的问题?方法 以下代码适用于304,不需要进一步渲染: 如果过时(:etag=>resource,:last\u modified=>resource.updated\u at.utc) 回应待办事项|格式| format.html#show.html.erb } 终止 结束 但是访问1.xml将尝试呈现资源两次: if stale?(:etag => resource, :last_modified => reso
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中的DoubleRenderError#显示
每个操作只能渲染或重定向一次
RAILS\u ROOT:/Users/guilherme/Documents/ruby/restfulie测试
应用程序跟踪|框架跟踪|完整跟踪
/Library/Ruby/Gems/1.8/Gems/actionpack-2.3.4/lib/action\u controller/base.rb:900:inrender\u而不使用\u benchmark'
/Library/Ruby/Gems/1.8/Gems/actionpack-2.3.4/lib/action\u controller/benchmarking.rb:51:in
render'
/Library/Ruby/Gems/1.8/Gems/activesupport-2.3.4/lib/active\u support/core\u ext/benchmark.rb:17:inms'
/Library/Ruby/Gems/1.8/Gems/activesupport-2.3.4/lib/active\u support/core\u ext/benchmark.rb:10:in
realtime'
/Library/Ruby/Gems/1.8/Gems/activesupport-2.3.4/lib/active\u support/core\u ext/benchmark.rb:17:inms'
/Library/Ruby/Gems/1.8/Gems/actionpack-2.3.4/lib/action\u controller/benchmarking.rb:51:in
render'
/Library/Ruby/Gems/1.8/Gems/actionpack-2.3.4/lib/action\u controller/base.rb:1331:insend'
/Library/Ruby/Gems/1.8/Gems/actionpack-2.3.4/lib/action\u controller/base.rb:1331:in
不使用过滤器执行操作'
/Library/Ruby/Gems/1.8/Gems/actionpack-2.3.4/lib/action\u controller/filters.rb:617:incall\u filters'
/Library/Ruby/Gems/1.8/Gems/actionpack-2.3.4/lib/action\u controller/filters.rb:610:in
perform\u action\u而不使用\u benchmark'
/Library/Ruby/Gems/1.8/Gems/actionpack-2.3.4/lib/action\u controller/benchmarking.rb:68:inperform\u action\u
/Library/Ruby/Gems/1.8/Gems/activesupport-2.3.4/lib/active\u support/core\u ext/benchmark.rb:17:in
ms'
/Library/Ruby/Gems/1.8/Gems/activesupport-2.3.4/lib/active\u support/core\u ext/benchmark.rb:10:inrealtime'
/Library/Ruby/Gems/1.8/Gems/activesupport-2.3.4/lib/active\u support/core\u ext/benchmark.rb:17:in
ms'
/Library/Ruby/Gems/1.8/Gems/actionpack-2.3.4/lib/action\u controller/benchmarking.rb:68:inperform\u action\u
/Library/Ruby/Gems/1.8/Gems/actionpack-2.3.4/lib/action\u controller/rescue.rb:160:in
不使用flash执行动作
/Library/Ruby/Gems/1.8/Gems/actionpack-2.3.4/lib/action\u controller/flash.rb:146:inperform\u action'
/Library/Ruby/Gems/1.8/Gems/actionpack-2.3.4/lib/action\u controller/base.rb:532:in
send'
/Library/Ruby/Gems/1.8/Gems/actionpack-2.3.4/lib/action\u controller/base.rb:532:inprocess\u无过滤器
/Library/Ruby/Gems/1.8/Gems/actionpack-2.3.4/lib/action_controller/filters.rb:606:in
process'
/Library/Ruby/Gems/1.8/Gems/actionpack-2.3.4/lib/action\u controller/base.rb:391:inprocess'
/Library/Ruby/Gems/1.8/Gems/actionpack-2.3.4/lib/action\u controller/base.rb:386:in
call'
/Library/Ruby/Gems/1.8/Gems/actionpack-2.3.4/lib/action\u controller/routing/route\u set.rb:437:in'call'
有什么建议吗
关于我不确定你是否找到了这个问题的解决方案,但我只是在渲染js时遇到了同样的问题 我找到的解决方案是使用相反的方法:
def index
if stale?(:etag => [request.host],
:public => true)
respond_to do |format|
format.js
end
end
end
当然,将[request.host]替换为您用来确定新鲜度的任何东西。为什么要将
:controller=>self
传递给to_xml
?Restfulie。。。github.com/caelum/restfulie