1
在我的Rails應用程序4.2我有一個index
行動,列出了所有用戶的發票,通過搜索參數的URL過濾:如何將GET參數傳遞給Ruby on Rails中的下一個控制器動作?
class InvoicesController < ApplicationController
def index
@invoices = current_user.invoices.search(params)
respond_to do |format|
format.html do
@title = "Invoices"
...
end
format.csv do
headers['Content-Disposition'] = "attachment; filename=\"#{invoices_filename}.csv\""
end
format.xls do
headers['Content-Disposition'] = "attachment; filename=\"#{invoices_filename}.xls\""
end
end
end
...
end
這工作得很好。用戶可以通過各種參數來過濾他的發票,並且列出的發票相應地進行調整。
當用戶想要以XLS或CSV格式下載這些確切發票時,就會出現問題。我有一個index.html.erb
鏈接爲:
<%= link_to "Download invoices", invoices_path(:format => "xls") %>
然而,下載所有的發票,而不僅僅是用戶過濾掉前面的人。
有沒有辦法將搜索參數傳遞給下一個動作或者更優雅的解決方案?
感謝您的任何幫助。
就是這樣。謝謝! – Tintin81