【发布时间】:2020-01-19 15:22:27
【问题描述】:
我的TasksController 中有这个index 方法:
def index
@tasks = current_account.tasks
@count = @tasks.length
respond_to do |format|
format.html do
...
end
format.zip do
if @count > 100
flash[:notice] = "Please reduce the number of tasks!"
redirect_to :action => "index", :format => "html"
else
DownloadArchive.call(@tasks)
end
end
end
end
如果有超过 100 个任务,我如何呈现我的索引操作的 html 版本?
我上面的代码不起作用。它下载html 文件,而不是重定向和显示flash 消息。我不明白为什么。如果可以,请帮助我。
【问题讨论】:
-
下载html文件的原因是
format.zip设置了Content-Disposition标头。所以你用headers['Content-Disposition'] = "inline"覆盖标题。但@lacostenycoder 的回答可能是一个更好的主意。
标签: ruby-on-rails ruby applicationcontroller