2013-08-27 123 views
2

我觉得我很想念这里真的很简单...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 

什么!这里错了!?

+3

能不能请你通过'http:不是'HTTP 3000 /更新/下载/ test'://本地主机: //localhost:3000/updates/download/test.zip'...让我知道...谢谢 –

+0

谢谢你!这是问题!很简单,但我没有看到它。 – Apollo

+0

谢谢@Apollo –

回答

0

能不能请你http://localhost:3000/updates/download/test代替http://localhost:3000/updates/download/test.zip ...让我知道...谢谢

0

感谢Rajarshi Das

由于点而发生错误!

我改变了routes.rb中要做到这一点,而不是:

match "updates/download(/:filename)" => "updates#download", :as => :getupdate, :constraints => { :filename => /[^\/]+/ } 

我真的很感激!我花了很多时间在这里!

+0

如果他帮你解决问题,你应该把他的答案标记为正确的 – dax

+0

当我得到答案时,它只是一个评论。我已经标记了正确的答案。你能否删除倒票? – Apollo