Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在ruby中不使用xml呈现时刷新_Ruby_Caching_Etag - Fatal编程技术网

在ruby中不使用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

在尝试在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 => 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:in
render\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:in
ms'
/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:in
ms'
/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:in
send'
/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:in
call\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:in
perform\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:in
realtime'
/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:in
perform\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:in
perform\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:in
process\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:in
process'
/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