我觉得我很想念这里真的很简单...Rails“无路由匹配”
我有几个文件意味着从我的应用程序的公用文件夹下载。要正确处理它,我做了这样一个类:
class UpdatesController < ApplicationController
def download teste
if params[:filename]
file_path = "#{Rails.public_path}/download/#{params[:filename]}"
send_file file_path, :filename => "#{params[:filename]}", :disposition => 'attachment'
end
end
end
现在,我的routes.rb样子:
match "updates/download/:filename" => "updates#download", :as => :getupdate
我的文件链接,像这样:好吧
<%= link_to "Download this thing", getupdate_url(:filename => entry.file_name) , :class => "btn btn-mini" %>
,url生成正确,我被重定向到正确的地址:
http://localhost:3000/updates/download/test.zip
而且我得到以下信息:
No route matches [GET] "/updates/download/test.zip"
在我的控制台我输入rake routes
,我得到这个:
$ rake routes
getupdate /updates/download/:filename(.:format) updates#download
该文件是在以下路径:
.../myapp/public/download/test.zip
什么!这里错了!?
能不能请你通过'http:不是'HTTP 3000 /更新/下载/ test'://本地主机: //localhost:3000/updates/download/test.zip'...让我知道...谢谢 –
谢谢你!这是问题!很简单,但我没有看到它。 – Apollo
谢谢@Apollo –