我是 Ruby on Rails 的新手。我正在使用 Ruby 2 和 Rails 4。我想使用 rails 下载文件。但是当我输入路径时,它不会显示 html 页面,而是会打开一个下载框并单击“确定”它会下载。我的代码如下。如果有任何机构可以,请帮助我。谢谢你。
在控制器中:
def download
send_file(
"#{Rails.root}/public/robots.txt",
filename: "robots.txt",
type: "application/txt"
)
end
在 download.html.erb 中:
<%= link_to 'Download', academics_download_path(:format => "txt") %>