[英]How to pass GET parameters to next controller action in Ruby on Rails?
在我的Rails 4.2应用程序中,我有一个index
操作,该操作列出了所有用户的发票,并按URL中的搜索参数进行了过滤:
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") %>
但是,它会下载所有发票,而不仅仅是用户以前过滤掉的发票。
有没有办法将搜索参数传递给下一个动作,或者也许是一个更优雅的解决方案?
谢谢你的帮助。
您只需要发送参数以及format
这将达到目的:
<%= link_to "Download invoices", invoices_path(params.merge(format: :xls)) %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.