2011-11-27 149 views
0

我試圖讓重定向:使用參數重定向失敗

redirect_to :controller => 'forex', :action => 'index', :format => :csv, :paramer =>  instrument_for_sql 

但在日誌中我有:

重定向到http://localhost:3000/forex/index.csv?paramer=AUDJPY 完成406無法接受在150ms的

但是,如果我貼http://localhost:3000/forex/index.csv?paramer=AUDJPY直接它工作。

任何想法?

class ForexController < ApplicationController 
def index 
instrument_for_sql = params[:paramer] 
receive_csv 
respond_to do |format| 
    format.csv 
end 
end 

routes.rb 
match '/forex', :controller => 'forex', :action => 'index', :format => 'csv' 
+0

檢查'paramer',它有錯誤,可能會導致問題 – megas

+0

請向我們展示您的'ForexController#index'操作。 –

+0

'paramer'可以。 –

回答

0

我解決了它。我試圖在respond_to塊中重定向。它在外面工作。當我在respond_to中使用format.html時,它也起作用。

respond_to do |format| 
format.html { redirect_to :controller => 'forex', :action => 'index', :format => :csv, :paramer => instrument_for_sql } 
0
def index 
    instrument_for_sql = params[:paramer] 
    receive_csv 
    redirect_to :controller => 'forex', :action => 'index', :format => :csv, :paramer =>  instrument_for_sql 
end 

試試這個,取出respond_to代碼塊。

+0

有問題的索引控制器不會重定向到它自己。這是不對的。 –

0

似乎Rails會在生成的url的情況下爲您設置響應格式,並返回406 error,因爲客戶端不接受這樣的響應。因此,嘗試替代:

  • redirect_to的url_for(:only_path =>真實,:控制器=> '外匯', :動作=> '索引',:格式=>:CSV,:paramer => instrument_for_sql)
  • redirect_to的url_for(:控制器=> '外匯',:動作=> '索引',:格式=>:CSV,:paramer => instrument_for_sql):狀態=> 301