2013-01-03 43 views
4

當你使用它時,我有一個頁面,上面有很多參數的大圖。ActionController :: Session :: CookieStore :: CookieOverflow當發送csv/xls文件時 - rails 2.3.5

所以我的控制器看起來是這樣的:

def report 
    # gather data for report 

    respond_to do |format| 
     format.html 
     format.xls { send_xls_file(@campaigns.uniq) } 
     format.csv { send_csv_file(@campaigns.uniq)} 
    end 

    def send_xls_file(campaigns) 
    @campaigns = campaigns 
    report_name = "CampaignReport.xls" 
    response.headers["Content-Disposition"] = "attachment; filename=#{report_name}" 
    end 

    # send csv does is similar but creates a csv using fastercsv. 

在爲XLS認爲我創建Excel文檔

現在,當我在頁面上一個很長的URL,並呼籲無論是XLS或CSV ,我得到這個錯誤:

Completed in 3189ms (View: 894, DB: 108) | 200 OK [https://myapp.com/campaign_metrics/report?mycampia%5B%5D=White+Paper+1&mycampia%5B%5D=Talk+Turkey+-+T&mycampia%5B%5D=Nicole+Book+-+T&mycampia%5B%5D=Make+the+Case+-+T&mycampia%5B%5D=Make+the+Case+-+L&mycampia%5B%5D=Make+the+Case+-+F&mycampia%5B%5D=Learn+Sewings+-+T&mycampia%5B%5D=Learn+Sewings+-+L&mycampia%5B%5D=Learn+Sewings+-+F&mycampia%5B%5D=Keys+-+T&mycampia%5B%5D=Keys+-+L&mycampia%5B%5D=Keys+-+F&mycampia%5B%5D=How+to+Tie+-+F&mycampia%5B%5D=Cartoon&mycampia%5B%5D=Best+Practice+SM+-+FB&mycampia%5B%5D=5+Reasons+Flat+-+T&mycampia%5B%5D=5+Reasons+Flat+-+L&top_mycampia%5B%5D=678&top_mycampia%5B%5D=681&top_mycampia%5B%5D=682&top_mycampia%5B%5D=683&top_mycampia%5B%5D=685&top_mycampia%5B%5D=686&top_mycampia%5B%5D=687&top_mycampia%5B%5D=688&top_mycampia%5B%5D=689&top_mycampia%5B%5D=690&top_mycampia%5B%5D=691&top_mycampia%5B%5D=692&top_mycampia%5B%5D=693&top_mycampia%5B%5D=694&top_mycampia%5B%5D=695&top_mycampia%5B%5D=696&top_mycampia%5B%5D=697&top_mycampia%5B%5D=698&top_mycampia%5B%5D=699&top_mycampia%5B%5D=700&top_mycampia%5B%5D=701&top_mycampia%5B%5D=702&top_mycampia%5B%5D=703&top_mycampia%5B%5D=704&top_mycampia%5B%5D=705&top_mycampia%5B%5D=706&top_mycampia%5B%5D=707&top_mycampia%5B%5D=709&top_mycampia%5B%5D=710&top_mycampia%5B%5D=722&top_mycampia%5B%5D=723&top_mycampia%5B%5D=724&top_mycampia%5B%5D=725&top_mycampia%5B%5D=726&top_mycampia%5B%5D=728&top_mycampia%5B%5D=729&top_mycampia%5B%5D=730&top_mycampia%5B%5D=731&top_mycampia%5B%5D=732&top_mycampia%5B%5D=733&top_mycampia%5B%5D=734&top_mycampia%5B%5D=735&top_mycampia%5B%5D=736&top_mycampia%5B%5D=737&top_mycampia%5B%5D=738&top_mycampia%5B%5D=739&top_mycampia%5B%5D=740&date_select_range=7%2F1%2F2012+-+12%2F31%2F2012&submit_action=Submit&graph_option=monthly&mycampia%5B%5D=White+Paper+1&mycampia%5B%5D=Talk+Turkey+-+T&mycampia%5B%5D=Nicole+Book+-+T&mycampia%5B%5D=Make+the+Case+-+T&mycampia%5B%5D=Make+the+Case+-+L&mycampia%5B%5D=Make+the+Case+-+F&mycampia%5B%5D=Learn+Sewings+-+T&mycampia%5B%5D=Learn+Sewings+-+L&mycampia%5B%5D=Learn+Sewings+-+F&mycampia%5B%5D=Keys+-+T&mycampia%5B%5D=Keys+-+L&mycampia%5B%5D=Keys+-+F&mycampia%5B%5D=How+to+Tie+-+F&mycampia%5B%5D=Cartoon&mycampia%5B%5D=Best+Practice+SM+-+FB&mycampia%5B%5D=5+Reasons+Flat+-+T&mycampia%5B%5D=5+Reasons+Flat+-+L&date_select_range=7%2F1%2F2012+-+12%2F31%2F2012&format=xls&graph_option=monthly&graphtype=Actual&report_type=export&sort=campaign&submit_action=Submit&top_mycampia%5B%5D=678&top_mycampia%5B%5D=681&top_mycampia%5B%5D=682&top_mycampia%5B%5D=683&top_mycampia%5B%5D=685&top_mycampia%5B%5D=686&top_mycampia%5B%5D=687&top_mycampia%5B%5D=688&top_mycampia%5B%5D=689&top_mycampia%5B%5D=690&top_mycampia%5B%5D=691&top_mycampia%5B%5D=692&top_mycampia%5B%5D=693&top_mycampia%5B%5D=694&top_mycampia%5B%5D=695&top_mycampia%5B%5D=696&top_mycampia%5B%5D=697&top_mycampia%5B%5D=698&top_mycampia%5B%5D=699&top_mycampia%5B%5D=700&top_mycampia%5B%5D=701&top_mycampia%5B%5D=702&top_mycampia%5B%5D=703&top_mycampia%5B%5D=704&top_mycampia%5B%5D=705&top_mycampia%5B%5D=706&top_mycampia%5B%5D=707&top_mycampia%5B%5D=709&top_mycampia%5B%5D=710&top_mycampia%5B%5D=722&top_mycampia%5B%5D=723&top_mycampia%5B%5D=724&top_mycampia%5B%5D=725&top_mycampia%5B%5D=726&top_mycampia%5B%5D=728&top_mycampia%5B%5D=729&top_mycampia%5B%5D=730&top_mycampia%5B%5D=731&top_mycampia%5B%5D=732&top_mycampia%5B%5D=733&top_mycampia%5B%5D=734&top_mycampia%5B%5D=735&top_mycampia%5B%5D=736&top_mycampia%5B%5D=737&top_mycampia%5B%5D=738&top_mycampia%5B%5D=739&top_mycampia%5B%5D=740&visits=on] 
/!\ FAILSAFE /!\ Thu Jan 03 12:33:51 +0000 2013 
Status: 500 Internal Server Error 
ActionController::Session::CookieStore::CookieOverflow 
/usr/lib64/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/session/cookie_store.rb:102:in `call' 
/usr/lib64/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/failsafe.rb:26:in `call' 
/usr/lib64/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `call' 
/usr/lib64/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `synchronize' 
/usr/lib64/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `call' 
/usr/lib64/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:106:in `call' 
/usr/lib64/ruby/gems/1.8/gems/passenger-3.0.17/lib/phusion_passenger/rack/request_handler.rb:96:in `process_request' 
/usr/lib64/ruby/gems/1.8/gems/passenger-3.0.17/lib/phusion_passenger/abstract_request_handler.rb:516:in `accept_and_process_next_request' 
/usr/lib64/ruby/gems/1.8/gems/passenger-3.0.17/lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop' 
/usr/lib64/ruby/gems/1.8/gems/passenger-3.0.17/lib/phusion_passenger/classic_rails/application_spawner.rb:321:in `start_request_handler' 
/usr/lib64/ruby/gems/1.8/gems/passenger-3.0.17/lib/phusion_passenger/classic_rails/application_spawner.rb:275:in `send' 
/usr/lib64/ruby/gems/1.8/gems/passenger-3.0.17/lib/phusion_passenger/classic_rails/application_spawner.rb:275:in `handle_spawn_application' 
/usr/lib64/ruby/gems/1.8/gems/passenger-3.0.17/lib/phusion_passenger/utils.rb:470:in `safe_fork' 
/usr/lib64/ruby/gems/1.8/gems/passenger-3.0.17/lib/phusion_passenger/classic_rails/application_spawner.rb:270:in `handle_spawn_application' 
/usr/lib64/ruby/gems/1.8/gems/passenger-3.0.17/lib/phusion_passenger/abstract_server.rb:357:in `__send__' 
/usr/lib64/ruby/gems/1.8/gems/passenger-3.0.17/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop' 
/usr/lib64/ruby/gems/1.8/gems/passenger-3.0.17/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously' 
/usr/lib64/ruby/gems/1.8/gems/passenger-3.0.17/lib/phusion_passenger/abstract_server.rb:180:in `start' 
/usr/lib64/ruby/gems/1.8/gems/passenger-3.0.17/lib/phusion_passenger/classic_rails/application_spawner.rb:149:in `start' 
/usr/lib64/ruby/gems/1.8/gems/passenger-3.0.17/lib/phusion_passenger/spawn_manager.rb:219:in `spawn_rails_application' 
/usr/lib64/ruby/gems/1.8/gems/passenger-3.0.17/lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add' 
/usr/lib64/ruby/gems/1.8/gems/passenger-3.0.17/lib/phusion_passenger/spawn_manager.rb:214:in `spawn_rails_application' 
/usr/lib64/ruby/gems/1.8/gems/passenger-3.0.17/lib/phusion_passenger/abstract_server_collection.rb:82:in `synchronize' 
/usr/lib64/ruby/gems/1.8/gems/passenger-3.0.17/lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize' 
/usr/lib64/ruby/gems/1.8/gems/passenger-3.0.17/lib/phusion_passenger/spawn_manager.rb:213:in `spawn_rails_application' 
/usr/lib64/ruby/gems/1.8/gems/passenger-3.0.17/lib/phusion_passenger/spawn_manager.rb:132:in `spawn_application' 
/usr/lib64/ruby/gems/1.8/gems/passenger-3.0.17/lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application' 
/usr/lib64/ruby/gems/1.8/gems/passenger-3.0.17/lib/phusion_passenger/abstract_server.rb:357:in `__send__' 
/usr/lib64/ruby/gems/1.8/gems/passenger-3.0.17/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop' 
/usr/lib64/ruby/gems/1.8/gems/passenger-3.0.17/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously' 
/usr/lib64/ruby/gems/1.8/gems/passenger-3.0.17/helper-scripts/passenger-spawn-server:99 

我不是故意存儲我的會話任何東西,它似乎像Rails是可能把URL進入會議及其太大了?有任何想法嗎?

+1

你是否在使用類似設計的東西?在你嘗試訪問一個url但它沒有被授權的情況下,它將url存儲在一個會話中。登錄後,它會重定向您。 –

+0

此外,你應該保持url少於2000個字符。 [什麼是URL的最大長度](http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url) –

+0

使用清除,也許多數民衆贊成,它是好主意,我會深入研究它。同意網址。 – Joelio

回答

1

看起來像是在會話中存儲長網址 - 可能清除? - 那是造成你的問題。

2

您可能會考慮將會話存儲移至ActiveRecord而不是Cookie。如果您對當前的.xls處理的執行情況沒有問題,這將是一個簡單的解決方法。問題出在Cookies存儲空間有限的情況下:4 kb。

如果您決定遷移到ActiveRecord的會話存儲,這裏的步驟:

  • app/config/initializers/session_store.rb文件

    改變商店:active_record_store

  • ,那麼你應該rails generate session_migrationrake db:migrate

您可能會想到另一種會話存儲:Memcache。它速度更快,在某些情況下使用更舒適。

+0

嗨,我沒有特意在會話中存儲任何東西,所以我的問題不是專注於移動會話存儲,而是解決我的問題(弄清楚會話中存儲什麼內容以及爲什麼) – Joelio

+0

在您當前的實現中,您正在使用長URL,這會導致將其存儲在會話存儲中。祝你好運,解決問題。 –

0

您收到此錯誤是因爲您的會話超出了4kb的限制。

試試這個

在數據庫中創建表的會話。

rake db:sessions:create 
rake db:migrate 

在配置/初始化/ session_store.rb 註釋行

Application.config.session_store :cookie_store 

並添加

Application.config.session_store :active_record_store 
1

錯誤信息清晰表明cookie存儲大小的溢出問題。

您的會話(默認情況下在cookie中)需要移動到活動記錄存儲或Memcache存儲來解決此問題。

對於存入數據庫會話:

config.action_controller.session_store = :active_record_store 

您需要創建的會話表如下

rake db:sessions:create 
rake db:migrate 

OR

對於內存緩存會話:

config.action_controller.session_store = :mem_cache_store 

而且你甲腎上腺素編輯設置一個內存緩存服務器,並將其配置爲如下

config.cache_store = :mem_cache_store, 'localhost', '127.0.0.1:11211', 
{:namespace => 'myapp123'} 
相關問題